Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am building an Android app which uses activity and fragments and rest calls and a local database. Does anybody know where REST calls is ideal to be placed. I am more interested for fragments but would also like to know about activities as well. I also have a local SLQLite database and I have a method for getting the data. Because a database operation is long running is that similar to a REST call?
Thank you
You SHOULD NOT place long-running operations or any model logic on classes that can be destroyed by configuration changes (rotations, screen changes, phone states), these classes are designed to render the UI to the user.
You should instead use:
ViewModel (for shorter tasks, will only survive as long as the app does) and use a background thread.
https://developer.android.com/topic/libraries/architecture/viewmodel?gclid=Cj0KCQjw09HzBRDrARIsAG60GP-qiuPnYKryrX2YYZI39988xMfqTx4s6fuk5xfKtvuPZ-XQ98DxpgEaAphmEALw_wcB
Services (Recommended, can survive despite your app not being active), make sure to check out the documentation first and some examples.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 months ago.
Improve this question
I was working in existing application in which it has more than 5 api calls in the viewmodel through retrofit. When fetching api call it has showing loader to main screen and block user untill we get data from response. Some are dependent to each other but some are not i.e. Login session dependent on customer data etc. All response are huge in data so may be it taking time to load. I read the review from play store, its frustrations for user and giving bad reviews. This project is growing day by day. I know you guys asked why this api calls in single screen and reason behind this is the application is healthcare. We make a survey from customer and they want there results in homepage. I already read the doc and everything is up to according to doc. I don't want spoonfed, but I need guidance for you guys. Many thanks
I had a similar case where I had multiple api calls and it was so difficult to handle the ui state and dealing with loading and failure.
We can separate those api calls, there is calls that depends from each other so they can't be in parallel and there is calls that can be in parallel.
I made a loading state for each call and I separate the loading UI ( I used skeleton loader ), So each part of the UI is able to have a loading by itself not a loading state for the whole screen ( loading for the user picture, loading for posts, loading for categories... ).
And then I'm able to handle the success of each call alone, so if call 1 succeeded I will set the content related to call 1 and the other parts of the UI will remain on loading state waiting for their content, so each part of the screen is related to the calls responsible for returning the content of that part.
So no need to keep the loading state for the entire screen until all the calls finished.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
when I use serializible to store data from an Android app in the internal storage, is there a danger of losing data, or does the data remain safed, even after an update?
App data remains after an app update or a system update. It does not survive the app being uninstalled and reinstalled. However, app data back up might be what you are looking for. Consult the docs here for more info.
If you are serializing your own classes, and the classes might change as your app is updated, there are additional issues (independent of Android) that you need to consider. See, for example, this question.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm recently started programming in Android Studio with Java, i don't have enough Knowledge in Building Mobile Applications.
So, my question is, if making a Class of methods for the logic of the application or make the methods in Activity Label.
Or if anyone experienced can give me a good advice.
If I understand your question correctly, it depends on where do you plan to use your methods. Are they limited to just one activity? Or will you be using those methods across several activities? If just for one activity then no need for another class to put those methods in as you will be using them in only one! On the other hand, if you plan to use the same method in several classes then putting those common methods in a single class is better
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In my App for Tablet! welcome activity, login activity, registration activity, password activity, starter activity with viewPager,
Message to send activity, scanning activity,
fill in form details activity, payment activity its about 25 activities with 25 layouts, 30 XML in Drawable for components background
and few images,fonts as of now
My Question is Since these individual activities include API call can I use fragment to reduce the activity, just because now
my app is 3.31 MB it further may increase and by reducing activity increases performance of my app, So which is best Fragment or Activity? Thanks in advance
Using fragments certainly helps since they make your code very modular and reusable. If you have multiple parts of the screen that are similar in nature, you can simply use fragments to create them. In terms of the api calls and the business logic, you could consider using MVVM architecture for your app. That way you can have a common ViewModel for fragments that make similar api calls and in doing so you make the business logic somewhat reusable too. Some resources that you might find useful for MVVM:
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel
https://developer.android.com/topic/libraries/architecture/viewmodel
Previous Stackoverflow post about fragments and app size:
How to reduce android activity and app size?
It does sound like using fragments would be the way to go for your app too as opposed to using 25+ activities.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
can you explain why does not allow network access in the main thread of a process in Android?
If anybody can explain. Its will be helpful for me.
Because the main thread is responsible for all the UI (user interface) operations (it is also called the UI thread). Everything related to displaying stuff in the screen is done by it. So if you occupy the main thread with long operations such as a network operation, you will experience jitter in the screen and even ANR errors (Application Not Responding). In more recent versions of Android you will not even be allowed to do that as the application throws NetworkOnMainThreadException.
Till Donut it is used to create multiple threads from 1.6-2.3 that you was using before but if now you are using 3.0 or above then it is used to create single threaded model by using AsyncTask otherwise you ll get the NetworkOnMainThreadException.