android-lifecycle

Current activities onResume() is not called when another Activity is launched from lock screen via notification

假装没事ソ 提交于 2019-12-24 02:14:47
问题 I have two activities Activity2 and TestActivity . Activity2 shows notification when launched. TestActivity is launched when notification is clicked. Below is the code of Activity2.java . import android.app.PendingIntent; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import com.droidapp.apptest.R; public

Must I persist Activity data when onStop() fires?

不羁的心 提交于 2019-12-24 00:34:30
问题 I find the official documentation regarding the Activity lifecycle unclear. It's littered with words such as should and might which makes me wonder what I must . When it comes to the onStop()-method, the documentation says the following: Note: Because the system retains your Activity instance in system memory when it is stopped, it's possible that you don't need to implement the onStop() and onRestart() (or even onStart() methods at all. It's possible ? Do I or do I not? Lets say I have some

basics of android activity life cycle functions

社会主义新天地 提交于 2019-12-23 22:49:00
问题 I was testing out this code which shows which state an activity is in public class Activity101Activity extends Activity { String tag = "Lifecycle"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); setContentView(R.layout.activity_activity101); Log.d(tag , "In the onCreate() event"); } public void onStart() { super.onStart(); Log.d(tag , "In the onStart() event");

Can Android kill my app while it is in the middle of a loop execution?

随声附和 提交于 2019-12-23 11:44:22
问题 When Android decides to remove an application from the stack in order to free up some RAM , what happens if the application that is being destroyed is currently running some loop in the background? Will the loop be terminated amid execution or will the VM wait for it to finish? 回答1: Will the loop be terminated amid execution or will the VM wait for it to finish? The loop is terminated, otherwise it isn't quite "killing". Simple test: public class MainActivity extends Activity { @Override

IllegalArgumentException when using Otto with a retained Fragment

可紊 提交于 2019-12-23 09:18:06
问题 I am using Otto 1.3.3 and when I resume my application sometimes I get an IllegalArgumentException with the following stacktrace: Caused by: java.lang.IllegalArgumentException: Producer method for type class com.couchsurfing.mobile.ui.setup .SessionProviderFragment$SessionConnectionStateChangeEvent found on type class com.couchsurfing.mobile.ui.setup.SessionProviderFragment, but already registered by type class com.couchsurfing.mobile.ui.setup.SessionProviderFragment. at com.squareup.otto.Bus

Application lifecycle when app is killed in the background

喜夏-厌秋 提交于 2019-12-23 04:17:34
问题 Some background on a problem that I have been encountering: in my app I have a singleton object that I use regularly to access things like id and token for network calls. Sometimes when the app is killed in the background, this singleton loses its state. However, when the app is opened again and starts up in some Activity past the launcher Activity , the singleton is null. I am in the process of refactoring this, but have been agonizing over how to ensure that the singleton will always be

In Android, how can I detect why my activity was resumed?

时光毁灭记忆、已成空白 提交于 2019-12-22 12:37:42
问题 I'm developing an Activity that does some of its own state management. I'm trying to differentiate the following onResume cases: New launch task switch (home button long-click) resume after other activity in the same application wake-up after sleep orientation change Is there something in the Activity's intent, or elsewhere, that can help me differentiate these? For the curious and some context... I'd like to preserve my internal history stack on 4 & 5. On cases 2 & 3, I would preserve the

What is lifecycle observer and how to use it correctly?

心不动则不痛 提交于 2019-12-22 07:02:01
问题 I have read about new architectural components in Android. So, i wanted to ask what are lifecycle observers and why do we need them? In what cases it is useful? Thanks for your answer! 回答1: You can use ProcessLifecycleOwner for Applications LifeCycle Event. You can implement Lifecycler Observer in your Application Class public class MyApplication extends MultiDexApplication implements LifecycleObserver @Override public void onCreate() { super.onCreate(); ProcessLifecycleOwner.get()

Application Level onResume Android

淺唱寂寞╮ 提交于 2019-12-22 05:10:33
问题 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

Crash upon screen being unlocked

天涯浪子 提交于 2019-12-21 22:02:17
问题 My app runs fine besides when the user stops using their phone long enough for the screen to lock, when they unlock it the app crashes and im a bit clueless as to why. Here is the error: here is the lazy adapter: package com.buhz.helpers; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View