android-lifecycle

Android - save value of member field in Fragment class

僤鯓⒐⒋嵵緔 提交于 2019-12-02 06:30:21
I'm trying to do something using a boolean in a Fragment class each time the Fragment is displayed. Example My app launches, opens the FirstFragment and the boolean for the first time is always true , then I have an if clause that checks its value: if (FirstTime) { FirstTime = false; } else { // Other stuff here, cause it's not true. } Then, on the first time, when FirstTime is true , I do stuff like go to another Fragment . and when I return to Fragment1 and on my onCreate() , I do the same. It's always true , seems that it's refreshing or something. Then I thought that could be a problem

How do fragments of an activity get restored when the activity restarts?

走远了吗. 提交于 2019-12-02 05:23:18
问题 I am testing situation where a user goes into my app after the system has terminated the app process due to low RAM. I am seeing unexpected behavior and hoping to get some help. In my app, I have an activity, lets call it ActivityA , that immediately creates a fragment, Fragment A , and does a fragment replacement. FragmentA displays a ListView with two items in it. If the user clicks the first item, a second fragment, Fragment B is created and replaces FragmentA . Otherwise, another

Android getIntent on new activity is NULL when calling activity is destroyed

别来无恙 提交于 2019-12-02 05:17:36
Do you guys have a workaround for the following problem? In the onDestroy of a registration activity (when the user presses the back button) I call a new activity so the user can put in some final production data of that day and then the report is being e-mailed. The problem is that on the just started activity the call to getIntent returns null and I have to get the data from there. public void onDestroy(){ //unregister listeners, cancel timers etc. logOff(); super.onDestroy(); } protected void logOff(){ // collect data etc. // open new activity that asks for final production numbers Intent

How do I retrieve the previous fragment upon opening an app from background? (app that wasn't killed)

两盒软妹~` 提交于 2019-12-02 03:02:17
I have a pretty unique issue where I am trying to retrieve previous fragment that was there before I went to the homescreen via the current fragment( last visible fragment) Not to confuse any further, here's the steps to repro my issue 1 ) launch the mainactivity, from there open fragment A via a button click (say button A) 2) from fragment A , press another button ,say B, which will open fragment B. 3) Fragment B has a close and save button , pressing which leads me back to the previous backstack fragment A ( activity.backpressed()) 4) Now, I have a scenario where I am calling fragment B, by

Are there any callback methods for when the quick settings dropdown menu is opened?

雨燕双飞 提交于 2019-12-02 00:50:01
When I pull down the quick settings drop down menu while my app is opened and in the foreground, are there any callback methods called? I tried a few quicks tests and Activity.onWindowFocusChanged(boolean hasFocus) might work for you. It fires when I drag down quick settings but it will also likely fire for other reasons, like AlertDialogs. onWindowFocusChanged void onWindowFocusChanged (boolean hasFocus) Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible to the user. 来源: https://stackoverflow.com/questions

android save programmatically created views

随声附和 提交于 2019-12-02 00:15:24
I programmatically create a RelativeLayout with some other views inside it and add it to the parent which is defined in XML. But all the views (incl. the layout) that were created programmatically disappear after the activity is re-created. Do I need a SharedPreferences object to save the values and then re-create the layout or is there an easier way to save it? P.S. all new created views get an id assigned Do I need a SharedPreferences object to save the values and then re-create the layout You say that you are creating these widgets in onResume() . Your code in onResume() needs to know what

Is it possible for a callback method to be called after onDestroy?

爱⌒轻易说出口 提交于 2019-12-01 18:09:09
问题 In the latest version of my app, some users are experiencing a crash that I'm unable to reproduce. Currently only Samsung devices running Lollipop are having the issue, but that might just be coincidence. After analyzing the stack trace and relevant code, I think that I may have found the culprit. To test my assumption, I simplified the code to the snippet below: public class TestActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate

Lock screen triggers application lifecycle events of different activity

和自甴很熟 提交于 2019-12-01 16:50:37
问题 When I receive a Push message in a service that extends FirebaseMessagingService and I start an Activity in this class, then the following lifecycle events / methods get executed: Push Message starts VideoRingingActivity Start VideoRingingActivity onCreate disableLockScreen The screen switches from black to the lock screen, so it doesn't show the VideoRingingActivity onStart onResume onPause onStop Now the actual VideoRingingActivity is shown? I was expecting this to come up after

What Android methods are called when battery dies?

我与影子孤独终老i 提交于 2019-12-01 16:38:49
问题 When the battery on my Android device dies what methods in the Activity and Fragment classes (if any) are called during the "Powering Off" stage of the device? Also, if a user is currently looking at a screen in my app and they hold the power button and choose switch off, do the events called/not called coincide with when the battery is depleted and shuts down automatically? OnPause? OnStop? OnDestroy? OnDetach? Bonus: Will I have enough time to save a small amount of data to a web server? To

onDestroy() - to set or not to set instance variables to null?

爷,独闯天下 提交于 2019-12-01 15:08:07
Is it a good idea to specifically set the instance variables to null in onDestroy() callback of the activity? Something like this: @Override protected void onDestroy() { super.onDestroy(); mClassVariable1 = null; mClassVariable2 = null; mClassVariable3 = null; } If I remember correctly from Java SE, any references that are isolated & not connected to a running program & can be garbage collected anyways. So does this make the above superfluous? On the other hand, the lifecycle in mobile devices being different, would the above be a best-practice? I know it cannot hurt to do it, but sometimes