android-lifecycle

Android scenario where ondestroy() is called without onpause() or onstop()

别等时光非礼了梦想. 提交于 2019-12-03 02:38:21
A few days back I was asked to write down scenarios where ondestroy() is called without onpause() or onstop() being called. Is it possible. If yes please explain. If you try below code, you will find a scenario where onDestroy() is indeed getting called while onPause() and onStop() Life-cycle call backs are Skipped. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); finish(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.e("MainActivity", "onDestroy"); }

NavUtils.navigateUpTo() does not start any Activity

我是研究僧i 提交于 2019-12-03 01:20:05
问题 I have two activities MainActivity DeepLinkActivity I set up everything to use the NavUtils for navigating up like advised here, here and here. What I want to achieve is: Start DeepLinkActivity via a deep link Press up Go to MainActivity Everything works nicely as long as there is any task of my app in the recent apps. However, when I swipe away my app from the recent apps, it behaves like this: Swipe away my app from recent apps Start DeepLinkActivity via a deep link Press up My app closes,

Android fragments vs compound controls

╄→尐↘猪︶ㄣ 提交于 2019-12-02 19:10:43
Why should Android 3.0 fragments be used instead of compound controls? One can create a View inheritor or compound control once and use it everywhere. I've read http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html but did not find the answer. Henry The difference is that fragments have a life cycle (onPause, onCreate, onStart...) of their own. By having a life cycle, fragments can respond independently to events, save their state through onSaveInstanceState, and be brought back (i.e. such as when resuming after an incoming call or when the user clicks the back button).

details of Android application components destruction and recreation

一个人想着一个人 提交于 2019-12-02 19:07:30
Could someone push me in the direction of some concrete, trustworthy (and preferably concise) information on the following: The order in which components are destroyed and (where applicable)recreated by the system (Fragment, Activity, Activity's Threads/AsyncTasks/Timers, static data(when are classes unloaded?), Threads/AsyncTasks/Timers in other classes, host TabActivity, ActivityGroup, bound local Services, Application, process) both when the app is in the background, and in the foreground. At which points the destruction can stop (what states can be encountered upon return to the app - like

Properly skip login activity if already logged in

安稳与你 提交于 2019-12-02 17:41:28
My launcher icon currently starts the login activity. I've stored the logged in status in SharedPreferences. Is there any way to properly skip the login activity and go straight to the main activity without any UI glitches. All existing solutions involving finish() in onCreate() cause the login activity title to be briefly visible or some other brief blank screen UI glitch. Have a launcher acitivy with no UI that decides to open the MainActivity or the LoginActivity. You can declare no UI with: android:theme="@android:style/Theme.NoDisplay" Two other possible solutions: Just do it the other

Managing the Activity Lifecycle demo activity return to original A if Start A

。_饼干妹妹 提交于 2019-12-02 16:50:26
问题 I am trying out the demo provided by https://developer.android.com/training/basics/activity-lifecycle/index.html. I can see when I start B or C, a new activity B or C will be created, and if I Finish B or C it will be only one step backward, just like: creating A->B->C->B->C, then by finish C then B then C then B I will get to A. Although if I try to start A in the process, it will go to the original first A, just like: creating A->B->C, then I create A, it just become A(instead of A->B->C->A

Android - save value of member field in Fragment class

若如初见. 提交于 2019-12-02 15:12:45
问题 I'm trying to do something using a boolean in a Fragment class each time the Fragment is displayed. Example My app launches, opens the FirstFragment and the boolean for the first time is always true , then I have an if clause that checks its value: if (FirstTime) { FirstTime = false; } else { // Other stuff here, cause it's not true. } Then, on the first time, when FirstTime is true , I do stuff like go to another Fragment . and when I return to Fragment1 and on my onCreate() , I do the same.

NavUtils.navigateUpTo() does not start any Activity

六眼飞鱼酱① 提交于 2019-12-02 14:37:16
I have two activities MainActivity DeepLinkActivity I set up everything to use the NavUtils for navigating up like advised here , here and here . What I want to achieve is: Start DeepLinkActivity via a deep link Press up Go to MainActivity Everything works nicely as long as there is any task of my app in the recent apps. However, when I swipe away my app from the recent apps, it behaves like this: Swipe away my app from recent apps Start DeepLinkActivity via a deep link Press up My app closes, like when pressing back I debugged the code, and found out, that NavUtils.shouldUpRecreateTask()

onStop delays to be called when restarting activity

偶尔善良 提交于 2019-12-02 08:22:20
When restarting an Activity, onStop() from previous activity delays too much to be called. I am using this code to restart my activity PlayerActivity.java Intent playerIntent = getIntent(); playerIntent.putExtra(Constants.VIDEO_ID, videoId); playerIntent.putExtra(Constants.CATEGORY_ID, categoryId); playerIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); startActivity(playerIntent); Let's call PreviousPlayerActivity and NewPlayerActivity , the activity that was before and the new activity. (remembering that they are the same PlayerActivity). Sequence When restarting the app follows

java.lang.IllegalStateException: attempt to re-open an already-closed object On Orientation Change

▼魔方 西西 提交于 2019-12-02 07:53:35
I am using 1 Activity that inflates 2 fragments (2 panes) in case of sw600-land and 1 fragment case of sw600 both of the fragments implements LoaderManager.LoaderCallbacks I'm initializing loader by (in onStart ) getActivity().getSupportLoaderManager().initLoader(pm2_MAIN_LOADER_ID, null, this); then I closed the cursor in onLoadFinished (at the last line of it) giving me the error so I have tried to close it somewhere else as the answers that I found on StackOverflow as onDestroy giving the same error so when I can close the cursor? When using a CursorLoader with the Loader framework, you