android-lifecycle

Fragment getActivity returns null because onAttach not called yet, how to synchronize?

孤街浪徒 提交于 2019-12-12 02:09:28
问题 I have a customized Fragment tabulation application. At one moment I want to open one fragment when receiving such answer from server. And then call the processResult method inside this fragment. But I got null result from getActivity which I used inside the processing. How to wait for the cycle to end to call the process method from my main? Here is the code from main: @Override public void onDeleteReservation(final SCHttpResult result, final SCWebServiceError err) { final Fragment f =

Restore activity after destruction ?(Activity Lifecycle) Help needed

末鹿安然 提交于 2019-12-12 00:27:58
问题 Hi guys i have an app which is almost totally complete.It is a music player.It plays music from a service. When i press back button that activity which started the service is obviously destroyed.(i want the activity to be destroyed so that the user can navigate other activities.The reason i am telling this is because singleton|singleinstance etc won't solve my problem) But i don't know how i can recreate the activity from the notification. Also when the activity which started the service is

How does viewPager retain fragment states on orientation change?

吃可爱长大的小学妹 提交于 2019-12-11 20:14:51
问题 This question has some similarities to: Fragment in ViewPager on Fragment doesn't reload on orientation change However the difference is that I want to know how the fragment states are actually retained as I observe a lot of weird things happening. My observations are the following: Setting up a ViewPager with a FragmentPagerAdapter: class HomeAdapter extends FragmentPagerAdapter { HomeAdapter(FragmentManager manager) { super(manager); } @Override public Fragment getItem(int i) { try { return

Which lifecycle callback is called when a fragment pager adapter's fragment comes to screen?

♀尐吖头ヾ 提交于 2019-12-11 19:58:26
问题 I want to detect when a particular fragment of three fragments I have set up with a ViewPager comes on to screen. I have 3 fragments in the viewpager and have set up the viewpager with mViewPager.setOffscreenPageLimit(2); so all three fragments are constructed at once (since it stores 2 on each side). I checked that Fragment.onResume() is called just once and not when each fragment comes to the foreground. Is there another callback to ensure I can catch this event and send some analytics

How to Handle Navigation between Dependent Activities

左心房为你撑大大i 提交于 2019-12-11 19:48:05
问题 My question is how to update an activity based on its child while maintaining the context supplied by its parent. See the example hierarchy below. There is a flow up and down. Using the app would go something like this: Select Team 1 on the Home activity --> Activity A inflates based on the selection. Select Player 2 on Activity A --> Activity B inflates based on the selection. Select to Add a Stat on Activity B --> Activity C inflates and allows a stat to be added. User returns to Activity B

Last opened activity

拈花ヽ惹草 提交于 2019-12-11 19:33:54
问题 My application on boot opens FirstActivity. From FirstActivity I can start: SecondActivity, ThirdActivity. When I press the Home button and then return to my app, it always opens FirstActivity, rather than opening the last activity (after returning start FirstActivity with onCreate() ). How I can restore application state on last activity? In code I don't start FirstActivity. My manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res

ListView gets empty when back icon is clicked

冷暖自知 提交于 2019-12-11 18:24:17
问题 I have two activities , in the main one I have a text field and two buttons , the user can enter text in the text field . When clicking the add button ,text will be added to some ArrayList . When clicking show in list button a new activity with its own fragment should open showing a listview that contains the names that the user has entered. I used ArrayAdapter and this is working fine. When I am in the list activity and when I click the back button of the device everything goes fine and the

UI updates across config changes: The weird point

只愿长相守 提交于 2019-12-11 17:55:09
问题 I am an experienced Android developer and it is a shame that I am still ineffectively fighting against fundamental issues like persisting UI changes across configuration changes. I know, this is an all too well known problem and there exists a lot of literature on it. The recommended solution is to setRetainInstance(true) a UI-less fragment: https://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html Best practice: AsyncTask during orientation change For the

Android onStop times out despite doing no work

十年热恋 提交于 2019-12-11 17:24:29
问题 I'm having trouble with an app crashing when returning to the activity. If I navigate away with the home button the phone (or emulator) onPause, onSaveInstanceState, and onStop are all called as per the lifecycle: 05-05 14:12:20.790 2043-2043/? I/myview: onPause was run 05-05 14:12:20.790 2043-2043/? I/myview: onSaveInstanceState was run 05-05 14:12:20.790 2043-2043/? I/myview: onStop was run Code in the activity: @Override protected void onPause(){ super.onPause(); Log.i("myview", "onPause

Destroyed fragment recreated and redestroyed when restarting the app

自闭症网瘾萝莉.ら 提交于 2019-12-11 14:27:47
问题 I'm trying do understand the lifecycle of Fragment . I have a MainActivity , with a layout including two FrameLayout to load Fragments , one for a top bar with a vertical menu, another one for the content. When I start the app, an instance of HomeFragment is loaded in the content FrameLayout container. Then when I click on a button in the menu, an instance of SomeFragment replaces it. When on the SomeFragment content, I click on the device's Home button, and all the visible Fragment (i.e. the