android-lifecycle

How did Android implement the checks for SuperNotCalledException?

白昼怎懂夜的黑 提交于 2019-12-05 19:27:30
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. 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 (!mCalled) { throw new SuperNotCalledException( "Activity " + mComponent.toShortString() + " did not call through

performing pause of activity that is not resumed after recreate method

为君一笑 提交于 2019-12-05 15:39:46
问题 I have a project for HoneyComb and I get an error after use recreate() method at onResum() method in my main Activity. 11-10 22:05:42.090: E/ActivityThread(1917): Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): at android.app

Does android save static variables?

折月煮酒 提交于 2019-12-05 09:13:11
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 the system passes to the method, if the app is being resumed from some inactive state. The logic is

Keeping threads and connection state in Android app using onSaveInstanceState?

大兔子大兔子 提交于 2019-12-05 07:59:11
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 talking about an app that is acting as a "server" for the game and it has open connections and threads that

Application Level onResume Android

放肆的年华 提交于 2019-12-05 06:03:20
Problem The idea is very simple. Whenever an user comes back to my app from the Recents I want to show a simple dialog prompting with the password. I know how to prompt the dialog with password, but my problem is how do I understand that the user has entered my app from the recents. If I put the prompt in the onResume in every activity, then it will get triggered everytime even if the user doesn't enter from the Recents menu. There are lots of activities and fragments in my app. So, I would love to have a more generic or application level solution. Implement Application

Flag Activity Clear Top destroys target activity and than creating it

二次信任 提交于 2019-12-05 05:22:49
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. Method onDestroy of A is also being called. Can anyone tell me is it proper or not? If i don't want

How to resume android app without losing activities stack (or the app state) with deep linking?

拟墨画扇 提交于 2019-12-05 01:10:35
问题 I have this <intent-filter> that every time certain link is pressed it opens my app but the problem is it opens a new instance of my app. Is there anyway to trigger onResume() and just resume my app without losing its state or the activities stack? This is the intent filter: <intent-filter> <data android:scheme="http" /> <data android:scheme="https" /> <data android:host="example.com" /> <data android:pathPattern="/.*" /> <action android:name="android.intent.action.VIEW" /> <category android

Why do OnCreate should be called only once on the start of Activity?

你离开我真会死。 提交于 2019-12-04 23:34:07
问题 I would like to know, why OnCreate() is called only once at the start of an activity? Can we call OnCreate() more than once in the same activity? If yes, than how can we call it? can anyone give an example? Thanks a lot!!! 回答1: Why would you want to called it again? unless the activity is reconstructed, which is called by system. You cannot call OnCreate manually , it is the same reason why you won't call setContentView() twice. as docs: onCreate(Bundle) is where you initialize your activity.

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

筅森魡賤 提交于 2019-12-04 22:32:49
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 populate the intent's extras, then why would it ever return null later? Is there a better place (like

Actionbarsherlock back button and smartphone back button

自作多情 提交于 2019-12-04 21:47:10
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 onCreate(Bundle savedInstanceState) { //setTheme(Principal.THEME); //Used for theme switching in samples