android-lifecycle

Don't restore ViewPager when Activity is restored

萝らか妹 提交于 2020-01-02 12:46:58
问题 The setup of my project is as follows Activity has Fragment and it has ViewPager with pages supplied by FragmentStatePagerAdapter . The data displayed by ViewPager is fetched from network. When Activity is destroyed and restored, it tries to restore the Fragment that was visible in ViewPager when the Activity was destroyed. But the Fragment inside the ViewPager tries to access data structures that are not fully initialized, as a result crash happens. I don't want the Fragment in ViewPager to

Handle app closing event from Launcher's menu

纵然是瞬间 提交于 2020-01-02 07:49:48
问题 What I want to do is to know when user closes the app from Android Launcher's menu, which gets opened on home button long click: I want to do some operations when user closes the app. Actually, I want user to logout each time he leaves the app, but as long as he can close app in this was too, I have to handle this event and then make my operations. I've tried to google this one, but I couldn't find anything considering this. I don't want to override onStop() or onDestroy(), as long as the

Flag Activity Clear Top destroys target activity and than creating it

给你一囗甜甜゛ 提交于 2020-01-02 03:12:28
问题 I am watching a behavior of Intent.FLAG_ACTIVITY_CLEAR_TOP. For example i have three activities A,B and C Now Flow is A -> B -> C Now when i am starting A from C with this flag with following code. Intent intent_to_a=new Intent(C.this,A.class); intent_to_home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent_to_a); AFAIK, Intent.FLAG_ACTIVITY_CLEAR_TOP should remove B and should resume the A .It also does the same but in a strange way. It removes B , than removes A than creates A

Stop handler after the fragment has been destroyed

試著忘記壹切 提交于 2020-01-01 08:30:15
问题 I have a Fragment which sets up a ListView and creates a Handler to update the Listview periodically. However, it looks like the Handler still runs after the Fragment has been destroyed. The following is the code. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //boilerplate code final Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { assignAdapter(); handler.postDelayed(this, 15000); } })

Android getIntent on new activity is NULL when calling activity is destroyed

独自空忆成欢 提交于 2019-12-31 03:58:08
问题 Do you guys have a workaround for the following problem? In the onDestroy of a registration activity (when the user presses the back button) I call a new activity so the user can put in some final production data of that day and then the report is being e-mailed. The problem is that on the just started activity the call to getIntent returns null and I have to get the data from there. public void onDestroy(){ //unregister listeners, cancel timers etc. logOff(); super.onDestroy(); } protected

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

App resuming results in crash with FormsAppCompatActivity

霸气de小男生 提交于 2019-12-30 18:53:18
问题 I have a Xamarin Forms app, currently being built for Android. I have a MainActivity that used to extend FormsApplicationActivity , but because I want to use a custom theme I had to change it to extend FormsAppCompatActivity (see my other question: Xamarin Forms custom theme not working). Ever since changing from FormsApplicationActivity to FormsAppCompatActivity the app crashes whenever I switch out of the app and then back into the app. It throws an error in the App.xaml.cs class in the

onDestroy() - to set or not to set instance variables to null?

╄→гoц情女王★ 提交于 2019-12-30 16:48:02
问题 Is it a good idea to specifically set the instance variables to null in onDestroy() callback of the activity? Something like this: @Override protected void onDestroy() { super.onDestroy(); mClassVariable1 = null; mClassVariable2 = null; mClassVariable3 = null; } If I remember correctly from Java SE, any references that are isolated & not connected to a running program & can be garbage collected anyways. So does this make the above superfluous? On the other hand, the lifecycle in mobile

Is instantiating an AsyncTask from a WakefulBroadcastReceiver recommended?

一曲冷凌霜 提交于 2019-12-30 11:01:42
问题 I can instantiate an AsyncTask from WakefulBroadcastReceiver (see my motivation for favouring AsyncTask over Service), e.g., public abstract class AlarmReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new AsyncTask<Void,Void,Void>(){ @Override protected Void doInBackground(Void... v) { while (true) { SystemClock.sleep(7000); Log.w("", "alive"); } } }.execute(); } } But is this recommendable? In particular, are there life cycle

Can some draw lifecycle of Fragment and its parent FragmentActivity?

雨燕双飞 提交于 2019-12-30 01:35:11
问题 In Android docs, I found a specs on Activity lifecycle and on Fragment lifecycle individually, but never together. It does not seem obvious as I attached a debugger to FragmentActivity which hosts my fragment, and the life cycle is more than crazy. It looks like activity finishes first and then fragments starts, which is impossible. Fragment's lifecycle Activity's lifecycle Logically, fragment should "jump into" activity's lifecycle after its onResume and it would end before activity's