activity-lifecycle

Confusion over the Android Activity Lifecycle

让人想犯罪 __ 提交于 2019-12-05 20:52:42
I have an app which is one activity. Everything works as I would expect except when I put the phone (a Samsung Galaxy Ace running Gingerbread) to sleep with the button on the side. When I do this, the following are called (in this order): onPause, onStop, onDestroy, onCreate, onStart, onResume, onPause . This is without waking the phone up , it is still asleep - screen is off. Why is the activity killed completely and re-recreated? Even more bizarre, if the phone is then switched back on the following happens: onResume, onPause, onStop, onDestroyed, onCreate, onStart, onResume Even though it's

How to prevent Android to restart application after calling camera intent?

家住魔仙堡 提交于 2019-12-05 20:43:03
On low memory device I've got a problem after calling camera intent. When activity result should be received Android restart the whole app. Have anybody faced same problem? Is there any solution? timoschloesser I faced the same issue a while ago: Android system stops application when launching Media Intent Apparently there is no solution, so you have to make sure that you save and restore the application state. Well i think, the problem could be: Image byte array is too big such that it touches the limit and android restarts the application so following is what will i do: Calling the intent

onStop vs onDestroy

耗尽温柔 提交于 2019-12-05 18:22:16
问题 I have tried to research exactly when the onDestroy method is called for an activity, but I've read some confusing and conflicting information. In general, my question is: under what circumstances is the onDestroy method actually called on an activity? More specifically, if I have two activities, activity A and activity B, if activity A is running and I create an intent and switch to activity B, is activity A only stopped, or is it destroyed? 回答1: Like stated in the official documentation:

getRunningAppProcesses() returns processes that were destroyed

对着背影说爱祢 提交于 2019-12-05 09:46:57
I am using the following snippet to check whether applications that I finish() ed are indeed no longer running: ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> procList = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo proc : procList) Log.d(TAG, proc.processName); } To my dismay, some applications that I finish() ed (in their Activity.onCreate(), even before they had a chance to launch anything), are still listed there. Why? LogCat shows that these applications' onDestroy() was definitely called

Android Storing Socket.io object for multiple activities

余生颓废 提交于 2019-12-05 04:31:25
问题 I am making my first Socket.io based android application. The socket sends and receives data from a web service. There are a number of screens in the application for different features. How do i use the same socket connection in these different activities. I have tried setting and storing the Socket Object in the Application class and it appears to work well but when the application goes into the background and left there for some time the application is killed and the socket object is then

Should I manually close HandlerThreads created by my application when destroying the activity?

落爺英雄遲暮 提交于 2019-12-05 02:45:26
My app is composed of a single Activity . In this activity, I'm creating multiple HandlerThread s which run in a loop to do socket blocking operations. Currently I post a quit message to everyone of these HandlerThread s during my Activity.onDestroy() . Sometimes, when I open my app, close it and relaunch it, it crashes (many time due to posting a message to a handler thread which is not running). My question is: What is the right way to close HandlerThread when I close my app? (Note that those threads might be blocking on a socket operation). EDIT: More information: I have a pool of Handler

Android - onStop() will be called with a delay

六月ゝ 毕业季﹏ 提交于 2019-12-05 01:34:57
I found my activities onStop() method will be called with a less than 10 seconds delay. I've never seen before this behavior. Note :- The activity is singleTop and it starts with Intent.FLAG_ACTIVITY_REORDER_TO_FRONT flag. Note :- I'm using Build Tools v23.0.2. The delay wasn't before and the method would be called immediately. I am guessing that you are starting another activity and you expect the current activity to receive an onStop() callback. According to the activity lifecycle , the onPause() method is called before the onStop(). In some cases onSaveInstance() is also called before the

Android View - What is automatically saved and restored in an Activity

混江龙づ霸主 提交于 2019-12-04 22:26:46
问题 I am a beginner with Android. In Android, some generic elements can be automatically saved/restored in onSaveInstanceState / onRestoreInstanceState . For example, an EditText saves/restores the Text property, a RatingBar saves/restores the Rating property... I see from some tests but I can't find anything about this in the documentation. How can I know what is saved/restored implicitly, without my intervention? For example, where I can find that the EditText.Text is automatically saved

Overlapping Fragments when resuming Activity

ⅰ亾dé卋堺 提交于 2019-12-04 17:29:19
I have a problem with my android app, I'm developing with Android STUDIO IDE. Pretty much when I leave the app in the background for a few minutes, or is killed by the system or I mix the different layouts of the fragment. I have put a picture below: I've already tried a variety of methods, if you have others write as well. Thank you in advance. super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager())); actionBar = getActionBar(); actionBar

Can an activity be killed with just onPause?

时间秒杀一切 提交于 2019-12-04 15:48:59
This is what I read from a book: The activity can be destroyed silently after onPause(). We should never assume that either onStop() or onDestroy() is called. But according to the documentation, Pause refers to partly visible, can an activity partly visible be killed without calling onStop or onDestory? There is no guarantee that onStop or onDestroy will be called. In situations when memory is severely lacking, the partially visible and out-of-focus Activity may be destroyed to reclaim resources. However, there is no guarantee that either of the two mentioned lifecycle methods will be called