android-lifecycle

App stops working when I call a second activity from nav drawer click

折月煮酒 提交于 2019-12-13 03:07:17
问题 When I click on the first position of my list view I want it to take me to another activity, and when I click on the second position I want it to take me to a different activity..etc. I have tried to write code that when I click on the first item of my list view it takes me to the activity "MrsClubb" but whenever I click on the item it comes up with the message "unfortunately "app name" has stopped working" and then the app closes. Any ideas? Here is the code for various bits of my app:

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

邮差的信 提交于 2019-12-13 01:42:53
问题 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

Android Lifecycle: Is onResume() supposed to be called during startup?

本秂侑毒 提交于 2019-12-12 13:50:24
问题 I'm trying an example from Android Application Development for Dummies , which is a simple app that toggles the ringing mode of the phone. The code is below. public class SilentModeToggleActivity extends Activity { private AudioManager mAudioManager; private boolean mPhoneIsSilent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); checkIfPhoneIsSilent();

How to run code when coming back to activity

左心房为你撑大大i 提交于 2019-12-12 11:51:14
问题 in my application I have 3 activities. First one -the main from which I start activity #2. From #2 I start #3 and at the same time I finish #2. When I finish #3 I automatically come back to #1. Question: How can I add/run code when coming back from 3 to 1? not sure if it makes sense. But what I want to do is, when ending #3 and coming back to #1 I want to check if file xyz exists and based on it to change UI in activity #1. OnResume in #1 is not ran, never. (Probably system doesn't run

Configuration change using Robolectric

限于喜欢 提交于 2019-12-12 11:07:30
问题 To retain my AsyncTasks across configuration changes, I use a fragment-based solution with setRetainInstance(true), which hosts each AsyncTask and calls back to a listening Activity, similar to this solution http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html Ultimately, the purpose is to test the AsyncTask's retention functionality throughout configuration changes using Robolectric, but I need to start with setting up the actual configuration change

Go back to Activity without recreating (without invoking onCreate())

筅森魡賤 提交于 2019-12-12 10:49:53
问题 I would like to ask similar question to: Go back to previous screen without creating new instance However I don't want Activity A go through onCreate callback, I would like to return to previous instance in the same state. How to achieve that without calling multiple finish() ? 回答1: There's no need to finish() activities as you navigate through your application. Instead, you can maintain your Activity back-stack and still achieve your goal. Let's say you have 4 activites like so: A --> B -->

Android fragment lifecycle issue with actionbar

帅比萌擦擦* 提交于 2019-12-12 05:15:55
问题 I want to realize the navigation of the fragments using the following code: public abstract class BaseFragment extends Fragment { private static String TAG = "BaseFragment"; private BaseFragmentActions baseFragmentActions; @Override public void onAttach(Context context) { super.onAttach(context); Activity activity = null; if (context instanceof Activity){ activity = (Activity) context; } Log.i(TAG, "onAttach = "); try { baseFragmentActions = (BaseFragmentActions)activity; } catch

Activity Lifecycle behaves differently JellyBean onwards

浪尽此生 提交于 2019-12-12 04:59:42
问题 I have the following scenario. Activity A starts Activity B. B starts a Notification clicking on which another activity C is started. Now the behaviour is different on Gingerbread and ICS onwards. Incase of Gingerbread when I click on the Notification, the expected behavior is seen, however when I run the same code on ICS or JellyBean when I click on the Notification Activity A is destroyed(OnDestroy is called). Why is the lifecycle behavior different. How can I make it to behave in a

How to access a start of Application (not Activity)

馋奶兔 提交于 2019-12-12 04:54:35
问题 I need to implement very specific code in the start of the application. I mean, not in the start of the activity(onCreate() or onStart()) but in the start of the application. I had one solution which is not good for me, which is to have a base activity called "MyBaseActivity" and then extends from it in all of my activities. This solution is not good for me, because this solution makes me to be able to do only one specific thing in the onCreate of each activity(the specific code I talked

Android : check when listview finish implementation or ready

ⅰ亾dé卋堺 提交于 2019-12-12 02:48:04
问题 PROBLEM I want to click Listview Programmatically after onResume() and retain ListView but I don't know when and where should I implement click logic because now it Force close because I call function to early (I have check return view is null) I use Handler() Runnable() and Thread() method becuase I think that this will queue my code after listview finish implementation. What should I do?? EXAMPLE OF USING HANDLER RUNNABLE and THREAD final Handler handler = new Handler(); Runnable runnable =