activity-lifecycle

What is the usage of onCreate method second implementation in Android Activities?

巧了我就是萌 提交于 2020-01-12 18:20:52
问题 I have alway used onCreate method inside my Activity lifecycle to start or restore from a saved state, but recently found that there is another onCreate method which contains a PersistableBundle : @Override public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); } I only found that it has been added since Android 21. Could anyone please give a complete information about this method, when it calls and the usage?

Stop service on swipe to remove

泄露秘密 提交于 2020-01-05 20:55:14
问题 App killed from Recently open application list by swipe. In my application, I am running service in background only when application is available in foreground or in background . If user has sent application in background by pressing home button of mobile then also service should be run . But when user remove application from recently opened application then 1) Is any methods invoke automatically when removed from recent app list? 2) Which method will be invoke? My Requirement: when

Why manage lifecycle through Application class?

陌路散爱 提交于 2020-01-05 08:12:18
问题 I was reviewing code from a chat demo application and I noticed that they created a class that extended Application, and inside the onCreate() was the following line registerActivityLifecycleCallbacks(new ActivityLifecycleHandler()); I then looked at the ActivityLifecycleHandler class and there were methods like public void onActivityDestroyed(Activity activity) { } public void onActivityPaused(Activity activity) { } public void onActivityCreated(Activity activity, Bundle savedInstanceState)

Will we leak the android service connection if the client's process is killed by android?

别等时光非礼了梦想. 提交于 2020-01-04 01:57:07
问题 Condition: I have a client activity "X" of a remote service (with AIDL) that calls the bindService() in the onCreate() and unbindService() in the onDestroy() . Assume that this activity has been started but not in the foreground ( onStop() has happened). It is said that when android system needs more memory elsewhere it might kill the process of another activity with less priority (possibly "X"). If, says, the android system decides to kill "X"'s process, according to the activity-lifecycle

Activity cannot be converted to LifecycleOwner

痴心易碎 提交于 2020-01-03 16:52:52
问题 I would like to use Room with LiveData, and in other projects I already used it, but in this one, I can not get it to work. It can't convert my activity into Lifecycle activity when I try to observe the livedata, however, I'm using the AppCompatActivity, and I even tried to Override the getLifecycle method (which worked for me in previous projects). I even tried with AndroidX but still the same issue :( Here my activity (Part of it): import androidx.appcompat.app.AppCompatActivity; import

Activity onStop() not called when home button is pressed in Android N multi window mode

主宰稳场 提交于 2020-01-03 07:28:07
问题 I am trying to make our video app to support Android N multiwindow mode. I have discovered that activity lifecycle becomes confused in multiwindow mode. The phenomenon is when our app layouts on the top screen with the whole screen in portrait, then I click the Home button, the upper app onPause() called but onStop() not called. According to the google guideline https://developer.android.com/guide/topics/ui/multi-window.html#lifecycle, video app should pause video playback in onStop()

Should I manually close HandlerThreads created by my application when destroying the activity?

安稳与你 提交于 2020-01-02 01:53:12
问题 My app is composed of a single Activity . In this activity, I'm creating multiple HandlerThread s which run in a loop to do socket blocking operations. Currently I post a quit message to everyone of these HandlerThread s during my Activity.onDestroy() . Sometimes, when I open my app, close it and relaunch it, it crashes (many time due to posting a message to a handler thread which is not running). My question is: What is the right way to close HandlerThread when I close my app? (Note that

Can an activity be killed with just onPause?

China☆狼群 提交于 2020-01-01 18:51:08
问题 This is what I read from a book: The activity can be destroyed silently after onPause(). We should never assume that either onStop() or onDestroy() is called. But according to the documentation, Pause refers to partly visible, can an activity partly visible be killed without calling onStop or onDestory? 回答1: There is no guarantee that onStop or onDestroy will be called. In situations when memory is severely lacking, the partially visible and out-of-focus Activity may be destroyed to reclaim

Are there any callback methods for when the quick settings dropdown menu is opened?

試著忘記壹切 提交于 2019-12-31 03:04:17
问题 When I pull down the quick settings drop down menu while my app is opened and in the foreground, are there any callback methods called? 回答1: I tried a few quicks tests and Activity.onWindowFocusChanged(boolean hasFocus) might work for you. It fires when I drag down quick settings but it will also likely fire for other reasons, like AlertDialogs. onWindowFocusChanged void onWindowFocusChanged (boolean hasFocus) Called when the current Window of the activity gains or loses focus. This is the

Simulate killing of activity in emulator

北城余情 提交于 2019-12-28 02:44:10
问题 I would like to test out onSaveInstanceState and onRestoreInstanceState for my app on the emulator. I have found this, which says that we could simulate this during orientation change, but I'm storing some of my variables on the application level (subclass android.app.Application ), so the orientation change does not wipe out the variables. So my question is, how can I simulate the low memory situation thus killing of my activities? Hope I've made myself clear. Thanks 回答1: You can pause your