android-lifecycle

How can I save the application back stack to a bundle?

倾然丶 夕夏残阳落幕 提交于 2019-12-09 12:56:02
问题 I'd like to save the state of my application so that when it is reopened from a closed state, the last fragment is visible and the back stack is preserved. I'd like to preserve this state every time the application is closed, not just on an orientation change or when the system kills the app to free up resources (as is the case when using onSaveInstanceState() / onRestoreInstanceState() . So far I've been able to restore the previous fragment and its state as planned by saving the state to

Activity onStart() being called before Fragment's onActivityCreated()

泪湿孤枕 提交于 2019-12-09 10:30:28
问题 I'm having an issue where my fragment's onActivityCreated() method is being called after my activity's onStart() method is called. This seems to imply that my activity's onCreate() method is finishing after onStart() ? That can't be the case ... Can it? When in my activity's lifecycle is my fragment's onActivityCreated() called? Furthermore, if I have multiple fragments, how can I control the order of the fragments' onActivityCreated() calls? In my activity: @Override protected void onStart()

Animation at the beginning of activity jumps

↘锁芯ラ 提交于 2019-12-09 10:06:51
问题 I am working on animating custom Views for my Android app. I have accomplished this via Property Animations and calling invalidate() on the View in the onAnimationUpdate() callback, as per https://developer.android.com/guide/topics/graphics/prop-animation.html: Depending on what property or object you are animating, you might need to call the invalidate() method on a View to force the screen to redraw itself with the updated animated values. You do this in the onAnimationUpdate() callback. My

Activity and Fragment Lifecycles and Orientation Changes

半城伤御伤魂 提交于 2019-12-09 04:44:52
问题 I have been having very odd issues with Fragments and orientation changes that have been causing force closes and not following a logical pattern. I created a simple Activity and Fragment lifecycle debugging application which simply implements every step of the Activity lifecycle and Fragment lifecycle by reporting the call to the logcat. Here are the TestActivity and TestFragment classes: TestActivity public class TestActivity extends Activity { Context ct = null; @Override protected void

ANDROID: Activity state after pressing the back button

丶灬走出姿态 提交于 2019-12-08 17:38:12
问题 Imagine you have the following sequence of activities: Activity A -> Activity B -> Activity C When you are on Activity C, pressing the native back button, takes you to Activity B. Now what is the state of Activity C? Is it still in memory or it has been finished? If it is still in the memory, is there a way to resume the activity? Other than starting another instance of this activity... I should add that this is the standard case where you do not use any flags including: FLAG_ACTIVITY_CLEAR

Application lifecycle when app is killed in the background

流过昼夜 提交于 2019-12-08 15:24:33
Some background on a problem that I have been encountering: in my app I have a singleton object that I use regularly to access things like id and token for network calls. Sometimes when the app is killed in the background, this singleton loses its state. However, when the app is opened again and starts up in some Activity past the launcher Activity , the singleton is null. I am in the process of refactoring this, but have been agonizing over how to ensure that the singleton will always be present even in app restart, but I'm not sure what Android does when the app restarts from being

ViewPager Current Fragment Visibility

懵懂的女人 提交于 2019-12-08 11:01:03
问题 What I Have I have a ViewPager with 5 fragments. I want to animate some TextViews inside the fragments whenever they become visible to the user. I can't use onResume() as the fragments to the left and right are already created. I can't use setUserVisibilityHint() as it is called before onCreateView() so the views are not ready yet. So what should be the way to animate the views whenever a particular fragment becomes visible to the user? 回答1: I'm not sure, but if you say that

Return to second activity after clicking home button

戏子无情 提交于 2019-12-08 10:12:15
问题 I've tried all launchMode's yet it does not seem to work: Suppose App A has various activities, J & K. J is the initial one (to choose app mode), which calls K where the main things happen (after calling it, J finish()es). If i click "Home" button in K, and then open the app again, it opens a new instance of A with activity J. I'd like it to open the paused K activity instead. Other threads mention an Android bug -- is there a way to fix it? Setting launchMode does not work :S Thanks a lot.

Is app process always killed when all Android components are destroyed?

佐手、 提交于 2019-12-08 07:33:31
问题 When all services are stopped, all broadcast receivers finished their jobs and no activities are running. Will always Android kill the app process? 回答1: Immediately? No. Your process will be a cached process, until such time as either your process is needed again or Android needs the system RAM for other processes. See the documentation for more. How long a process remains cached varies based on the amount of system RAM and how much activity is going on. It could be milliseconds. It might be

Is onDestroy called only if you explicitly call finish() ?? or are there any exceptions?

只谈情不闲聊 提交于 2019-12-08 05:20:48
问题 I have a LocalBroadcastReceiver and I am unregistering it in my ondestroy() . Now i read about ondestroy() mentioned in these two SO answers is-ondestroy-not-always-called and why-implement-ondestroy-if-it-is-not-guaranteed-to-be-called and as well as in Androi Docs that onDestroy will be called if you explicitly call finish(); But why in my case I am not calling finish() but still ondestroy() is getting called everytime in all of my Android devices. Also according to you guys where are the