android-lifecycle

Android - Performing stop of activity that is not resumed

南笙酒味 提交于 2019-11-26 15:31:56
问题 When I push my app to background, and do some other stuff like whatsapp or sms, onResume it works great. But I recently discovered that when I open/launch facebook app while my app is on background, I don't know what happens... But onResume, the app misbehaves... Don't do what it is required to do, but when I go back to homepage and come back it works fine Please help me out.. how to fix it ??? Logcat with all messages (without filter) 10-15 12:53:59.899: I/Adreno-EGL(32033): Remote Branch:

Should the call to the superclass method be the first statement?

一个人想着一个人 提交于 2019-11-26 15:20:00
问题 The results of a speech recognition can be read in the onActivityResult(int requestCode, int resultCode, Intent data) method, as shown in this example. This method overrides the same method in class Activity : why is the call to the superclass method not the first statement? @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { // Fill the list view with the strings the

Android lifecycle library ViewModel using dagger 2

倾然丶 夕夏残阳落幕 提交于 2019-11-26 15:18:28
问题 I have a ViewModel class just like the one defined in the Connecting ViewModel and repository section of Architecture guide. When I run my app I get a runtime exception. Does anyone know how to get around this? Should I not be injecting the ViewModel? Is there a way to tell the ViewModelProvider to use Dagger to create the model? public class DispatchActivityModel extends ViewModel { private final API api; @Inject public DispatchActivityModel(API api) { this.api = api; } } Caused by: java

Android: Under what circumstances would a Dialog appearing cause onPause() to be called?

故事扮演 提交于 2019-11-26 15:04:24
A snippet from the Android Activities document(scroll down to the " foreground lifetime " line) says : An activity can frequently transition in and out of the foreground—for example, onPause() is called when the device goes to sleep or when a dialog appears . I don't quite understand this. Under what circumstances should this happen? Is onPause() called only if the context of the dialog in question is different from the activity on top of which the dialog is to be displayed? EDIT: Adding code sample to illustrate my doubt in detail Going by the above-mentioned quote from document, should my

App restarts rather than resumes

懵懂的女人 提交于 2019-11-26 13:57:22
Hopefully someone can help me figure out, if not a solution, at least an explanation for a behaviour. The Problem: On some devices, pressing the launcher icon results in the current task being resumed, on others it results in the initial launch intent being fired (effectively restarting the app). Why does this happen? The Detail: When you press the "Launcher Icon" the app starts normally - That is, I assume, an Intent is launched with the name of your first Activity with the action android.intent.action.MAIN and the category android.intent.category.LAUNCHER . This can't always be the case

when is onRestoreInstanceState called?

三世轮回 提交于 2019-11-26 13:49:13
问题 Sorry for my incomprehension, but I am new in the android development. I have an application with activity A and activity B in it, and I go from activity A to activity B. When I left activity A, the onSaveInstanceState method was called, but when I went back to activity A (from activity B in the same application), the bundle in the onCreate method was null. What can I do, to save the activity A's previous state? I only want to store the data for the application lifetime. Can someone help me

When exactly are onSaveInstanceState() and onRestoreInstanceState() called?

纵然是瞬间 提交于 2019-11-26 12:52:56
问题 The following figure (from the official doc) describes the well-known lifecycle of an Android activity: On the other hand, when the activity is destroyed by the system (for example because memory needs to be reclaimed), the state of the activity is sometimes automatically saved and restored by means of the methods onSaveInstanceState() and onRestoreInstanceState() , as illustrated by the following figure (also from the official doc): I\'m aware that onSaveInstanceState() is not always called

Display fragment viewpager within a fragment

主宰稳场 提交于 2019-11-26 12:46:48
I have a fragment which contains a ViewPager. The ViewPager is associated with an adapter that contains a set of fragments. Upon loading the parent fragment, I am met with an IllegalStateException with the message: java.lang.IllegalStateException: Recursive entry to executePendingTransactions . Some research has led me to the conclusion that the system is unable display fragments within another fragment, HOWEVER there seems to be some indication that it is possible to do exactly this with the use of a ViewPager ( A bug in ViewPager using it with other fragment ). In fact, if I add a button to

How to handle AsyncTask onPostExecute when paused to avoid IllegalStateException

会有一股神秘感。 提交于 2019-11-26 11:55:44
问题 I appreciate the numerous postings regarding AsyncTask on a rotation change. I have the following problem when using the compatability lib and trying to dismiss a DialogFragment in onPostExecute . I have a fragment which fires of an AsyncTask which displays a progress DialogFragment , then in onPostExecute dismisses the dialog and then potentially throws up another DialogFragment . If when the progress dialog is being displayed I put the application into the background I get the following for

Activity.finish() called but activity stays loaded in memory

旧巷老猫 提交于 2019-11-26 11:27:38
问题 When I run my app on the debugger, I get the main thread and 3 binder threads. On a button click I call Activity.finish() , which looks like it ends the activity as the UI closes and goes back to the home screen. However, in the debugger, it still shows the main thread and 3 binder threads as \" (running) \". I am baffled to why this is happening. Even more so, it is causing my app to call Activity.onResume() when I run it again after exiting the app. I currently override these methods in the