android-lifecycle

Prevent activity from being destroyed as long as possible

人盡茶涼 提交于 2019-11-28 00:47:01
I have an app, a single activity app with fragments in it. The usual use case for this app is, that you start it and put the phone away and every now and then, you get back to the phone and insert some data... It's a logging app, you are doing something and insert your results into the app... I have the problem, that every now and then, my activity get's destroyed and is recreated with an empty bundle... (Most of the time this is not the case, but every now and then this happens...). My app sometimes starts a service, even this service is killed in this case... This means, that the system has

When can onTaskRemoved() be called?

送分小仙女□ 提交于 2019-11-27 23:57:44
问题 The docs state that This is called if the service is currently running and the user has removed a task that comes from the service's application. It seems as if it is only called when the app is swiped away from the recent task list. Pressing the back button until all Activities are destroyed in the task does not cause this to be called. Are there other scenarios where this could be called? 回答1: Pressing the back button until all Activities are destroyed in the task does not cause this to be

Main difference between Manifest and Programmatic registering of BroadcastReceiver

。_饼干妹妹 提交于 2019-11-27 20:36:05
I am trying to understand the main differences between registering a BroadcastReceiver in the Manifest and registering it programmatically... My understanding is basically as follows (would appreciate someone correcting my points if I am missing something). Registered in Manifest: The OS will magically find and instantiate your class if needed, calling the onReceive() method, regardless what the running state of your application was Your receive will only get called once per broadcast (i.e. You can consider that registering in the manifest is like registering your 'class' for receiving the

What is the difference between setContentView and LayoutInflater?

送分小仙女□ 提交于 2019-11-27 19:23:55
I am creating a tabs list with several fragments. I have noticed that, in the main activity, I used setContentView to get the layout xml and use findViewById to get the corresponding UI element config. setContentView(R.layout.fragment_tabs); mTabHost = (TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); mTabManager = new TabManager(this, mTabHost, android.R.id.tabcontent); However, in the different fragment class, I have to use the inflater instead. View v = inflater.inflate(R.layout.webview, container, false); WebView myBrowser=(WebView)v.findViewById(R.id.mybrowser); And both

How to use onResume()?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 18:26:43
Can anyone give me an example that uses onResume() in Android? Also, if I want to restart the activity at the end of the execution of another, which method is executed— onCreate() or onResume() ? And if I want to update data, how do I put it in onResume()? Mr.Sandy Any Activity that restarts has its onResume() method executed first. To use this method, do this: @Override public void onResume(){ super.onResume(); // put your code here... } Viswanath Lekshmanan Restarting the app will call OnCreate() . Continuing the app when it is paused will call OnResume() . From the official docs at https:/

Difference between onPause and onStop()

試著忘記壹切 提交于 2019-11-27 17:16:00
From android doc here http://developer.android.com/reference/android/app/Activity.html , it said 'Activity comes into foreground' will call onPause() , and 'Activity is no longer visible' will call onStop() . Isn't 'Activity comes into foreground' same as 'Activity is no longer visible'? Can you please tell me what is the difference between them? No, if some activity comes into foreground, that doesn't necessarily mean that the other activity is completely invisible. Consider the following case: Here we see both activities at the same time. The first activity with the fields is obscured by

When is the savedInstanceState bundle actually used?

╄→гoц情女王★ 提交于 2019-11-27 15:38:45
问题 Does anyone know of an exhaustive list of when the savedInstanceState bundle will be used in an activity? I know it's used when the device orientation changes. However, it doesn't seem to be used when the user force closes the app from the Android settings, but this might be due to something in my code. What other cases are there? To be clear, by "used" I mean when onCreate() is called, the savedInstanceState bundle is not null and contains the data I passed into it the last time

onCreate being called on Activity A in up navigation

ⅰ亾dé卋堺 提交于 2019-11-27 14:52:10
问题 So I have an Activity A and an Activity B. I want Activity A to be able to navigate to Activity B with the press of a button. That works, but when I use the up navigation(the home button in the action bar) to navigate back to Activity A, onCreate() is called again and the old information that the user typed in is lost. I've seen: onCreate always called if navigating back with intent, but they used Fragments, and I'm hoping not to have to redesign the entire app to use fragments. Is there any

DialogFrag#show() from a Fragment throwing “IllegalStateException: Can not perform this action after onSaveInstanceState”

守給你的承諾、 提交于 2019-11-27 14:47:37
问题 Just to be clear, I have read the dozen top SO questions on "IllegalStateException: Can not perform this action after onSaveInstanceState" and I have read Alex Lockwood's blog post on the issue http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html So I'm not asking this blindly. I have a very simple use case case that doesn't involve AsyncTask or any background processing. I have a Fragment that contains a button. On the onClickListener for the button, I

Why is onDestroy always called when returning to parent activity?

点点圈 提交于 2019-11-27 14:46:09
问题 I have a very simple app based on the Building Your First App tutorial. There are two activities: MainActivity invokes DisplayMessageActivity through startActivity() . When entering DisplayMessageActivity , I see: MainActivity.onStop() as expected, but when I press the back button to return to the parent MainActivity , I get: MainActivity.onDestroy() MainActivity.onCreate(null) MainActivity.onStart() The activity always gets destroyed for this very simple application. But according to the