activity-lifecycle

How to trigger onPause programmatically in android activity

本秂侑毒 提交于 2019-12-01 08:03:50
I am trying to work out how I can simulate pausing an activity for debugging my app. I want onPause to be called but NOT onStop. I just want to try a pause resume cycle and am looking for some code i can call (e.g. after a button press) to trigger this. Any ideas how? I have seen people suggest pressing the home button in other threads but when I do this is stops the app and calls onStop as well as onPause so it isn't quite what I was looking for. Taken from this link : The easiest is to add a semitransparent activity on top of your activity. I did the test myself and onStop is not called

How to trigger onPause programmatically in android activity

断了今生、忘了曾经 提交于 2019-12-01 06:22:01
问题 I am trying to work out how I can simulate pausing an activity for debugging my app. I want onPause to be called but NOT onStop. I just want to try a pause resume cycle and am looking for some code i can call (e.g. after a button press) to trigger this. Any ideas how? I have seen people suggest pressing the home button in other threads but when I do this is stops the app and calls onStop as well as onPause so it isn't quite what I was looking for. 回答1: Taken from this link: The easiest is to

Is it mandatory to remove yourself as an observer from Android Lifecycle?

一个人想着一个人 提交于 2019-12-01 03:02:51
I am building an Android Java class which implements the LifecycleObserver interface. This is the constructor: public MyObserver(AppCompatActivity activity) { this.mActivity = new WeakReference<AppCompatActivity>(activity); activity.getLifecycle().addObserver(this); } Is it necessary to ever call removeObserver , using something like: @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void destroyListener() { if (this.mActivity.get() != null) { this.mActivity.get().getLifecycle().removeObserver(this); } } Or, can I observe forever? TL;DR: Nope. According to this link here , where a user

Is it mandatory to remove yourself as an observer from Android Lifecycle?

↘锁芯ラ 提交于 2019-11-30 22:41:24
问题 I am building an Android Java class which implements the LifecycleObserver interface. This is the constructor: public MyObserver(AppCompatActivity activity) { this.mActivity = new WeakReference<AppCompatActivity>(activity); activity.getLifecycle().addObserver(this); } Is it necessary to ever call removeObserver, using something like: @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) public void destroyListener() { if (this.mActivity.get() != null) { this.mActivity.get().getLifecycle()

Determine if application on foreground - is that frowned upon?

青春壹個敷衍的年華 提交于 2019-11-30 15:47:40
There are lots of reasons why detecting if application is on foreground. for example - as a trigger to GCM/C2DM push notification - lot's of apps would have good reason implementing different behavior when app is foreground and background. Other reason could be - shotting down services consuming precious resources, such as querying servers in background task for instance. Just to be clear: the definition (as I see it) for background app is : application which none of it activities are invoked the onStart() method, and did not invoke yet the onStop() method. that's because activity is visible

Does onDestroy() or finish() actually kill the activity?

限于喜欢 提交于 2019-11-30 14:32:29
Actually I know i am asking about the simple and basic concept of Android. But I am a little bit confused about these finish() and onDestroy() methods. Whether this will kill the activity and free the resources associated with these activity? I tried with a simple application which contains only one activity. I thought the concept is like When the application runs, the activity will start. and when we click on back button, it will finish. And I gave some toast message inside each life cycle methods for knowing the memory usage . And when I clicked on the back button it executed onPause() ,

BufferQueue has been abandoned: When playing video with TextureView

不想你离开。 提交于 2019-11-30 05:09:02
Every time I pause my activity (actually Fragment) to go to another app, upon returning with onResume I try to resume the video playing but it does not play: I get a blank screen. Upon investigation, I see the following in the Logcat E/BufferQueueProducer: [unnamed-23827-0] queueBuffer: BufferQueue has been abandoned E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/BufferQueueProducer: [unnamed-23827-0] connect(P): BufferQueue has been abandoned Here is the code I call inside on resume player.seekTo(mVideoSeekPosition);

IllegalArgumentException with Otto Event bus in Fragment instance

佐手、 提交于 2019-11-30 00:36:14
I am using Otto Event bus to subscribe to certain events in a ListFragment. The bus instance is stored and created in an subclass of Application, in other words, it bus should work as a singleton. It seems like this is not a case... The fragment is registering to the bus in onActivityCreated(Bundle) and unregistering in onDestroy() . This does not work as it should. I have gotten several crash reports from devices where the app crashes when calling unregister() (java.lang.IllegalArgumentException: Missing event handler for an annotated method...). This exception is only thrown if unregister()

Does onDestroy() or finish() actually kill the activity?

孤者浪人 提交于 2019-11-29 20:42:52
问题 Actually I know i am asking about the simple and basic concept of Android. But I am a little bit confused about these finish() and onDestroy() methods. Whether this will kill the activity and free the resources associated with these activity? I tried with a simple application which contains only one activity. I thought the concept is like When the application runs, the activity will start. and when we click on back button, it will finish. And I gave some toast message inside each life cycle

Retrieve an activity after Time out warning notification

孤街醉人 提交于 2019-11-29 12:16:12
I'm trying to implement time out notification. Here is what I want to do. If app goes to the background mood, after 5 minutes it should warn the user that app will be signed out. After this notification, if user opens the app, it should ask for the password, if user inputs correct pass, it should retrieve the screen that he left 5 mins ago. My problem is that I cannot save the activity that user left in order to retrieve after they input password. Here is what I've done so far: I added a countdown inside of onSaveInstanceState() method, and create an instance of current intent. Then in