android-lifecycle

How to handle android lifecycle in flutter android plugin package

只谈情不闲聊 提交于 2019-12-08 02:27:11
问题 I need to know the current state of the flutter app view in an android plugin package. For now, I observe the state in the flutter view with https://docs.flutter.io/flutter/widgets/WidgetsBindingObserver-class.html and pass it then to my plugin. As this seems sometimes not perfect (the first event is not passed on Android) I would like to get the state directly from the android plugin. In the plugin I get the registrar and can its activity, but how do I observe the state of it? 回答1: Flutter

How did Android implement the checks for SuperNotCalledException?

∥☆過路亽.° 提交于 2019-12-07 12:03:46
问题 In the Activity class, Android provides runtime enforcement that super() must be called for overridden lifecycle callback methods. If you forget do do so, it throws SuperNotCalledException. Exactly how was this implemented specifically on Android? Please point me to the actual source implementation if possible. 回答1: It looks like they clear a flag in the super methods and check that it was set: final void performStart() { mCalled = false; mInstrumentation.callActivityOnStart(this); if (

Fragment's reference to mActivity becomes null after orientation change. Ineffective fragment state maintenance

风流意气都作罢 提交于 2019-12-07 10:05:55
问题 My application consists of several fragments. Up until now I've had references to them stored in a custom Application object, but I am beginning to think that I'm doing something wrong. My problems started when I realized that all my fragment's references to mActivity becomes null after an orientation change. So when I call getActivity() after an orientation change, a NullPointerException is thrown. I have checked that my fragment's onAttach() is called before I make the call to getActivity()

Does android save static variables?

允我心安 提交于 2019-12-07 06:39:50
问题 I'm writing a simple android application which is basically a modification of the fragments demo available in the android documentation. In the app, there is a file called Ipsum.java which has a static ArrayList of Strings called Headlines. In the onCreate() method of the main activity, I have the following code which adds some elements into the array list. if (savedInstanceState == null){ Ipsum.Headlines.add("String 1 "); Ipsum.Headlines.add("String 2"); } savedInstanceState is a Bundle that

What happens to android app when a phone call interrupts the app?

点点圈 提交于 2019-12-07 02:54:37
问题 I am working on an app and in one of my activities I display a progressdialog. I have managed it so that it displays correctly during rotations, and I thought that would handle the case of a phone call too, but when I test it with a phone call the dialog goes away. So what exactly does the phone call do to the application and how is a part of the application lifecycle? 回答1: onPause and onStop are called, onDestroy may be called but you can't rely on it. 回答2: Long-press your home button and

Keeping threads and connection state in Android app using onSaveInstanceState?

怎甘沉沦 提交于 2019-12-07 01:59:17
问题 I am developing a multi player game app for the android. One of the participant is acting as the host (the one who created the game instance) and each of the other participants is connecting to the host using bluetooth. My question is as follows, this host has some threads running in order to communicate and holds all the open connections. I've read that my Activities can be destroyed temporary and restored later and I should use the onSaveInstanceState mechanism for that. However, I am

In Activity.onCreate(), why does Intent.getExtras() sometimes return null?

匆匆过客 提交于 2019-12-06 16:55:39
问题 This was probably a false alarm, see my own answer. Original question below: An activity has a button that takes the user to another activity. To launch the new activity, we populate our Intent with extras, and onCreate(), the new activity reads from those extras via Intent.getExtras(). We assumed the returned bundle would be non-null, but as customer crash reports discovered, getExtras() sometimes returns null. Null-guarding the extras, as this answer shows, is perfectly fine, but if you

Actionbarsherlock back button and smartphone back button

喜夏-厌秋 提交于 2019-12-06 16:13:42
问题 The problem: I have the main activity that I want to callback when I press back button from either smartphone and actionbar on the second activity. But it always crash, it just work when I put a finish(); in the main activity, but If I do that then the back button from smartphone doesn't work properly. MainActivity: public class Principal extends SherlockActivity { public static int THEME = R.style.Theme_Sherlock; private Button entrar; private Button cadastrar; @Override protected void

Don't restore ViewPager when Activity is restored

ぃ、小莉子 提交于 2019-12-06 14:30:54
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 be recreated . One way that works is to pass null in super.Oncreate(savedInstance) of the Activity .

Android activity and fragment lifecycle issues in case of app minimization

半城伤御伤魂 提交于 2019-12-06 11:33:44
问题 I have a fragment with a multi-choice list. I am trying to save instance of the items that are checked in the list currently and restore them in case of app minimization and such. Steps of testing: Reach the multi-choice list fragment. Check a few list items Press the home key to minimize the app. Press the multitasking button and choose my app to restore it Following is the code that i am using: adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple