back-stack

Calling finish() does not clear memory references to Activity

时光毁灭记忆、已成空白 提交于 2019-12-02 10:17:38
问题 In a simplified version of my app, I have two activities, A and B. Actvity A starts B, and after some work B calls finish(). Using the Memory Analyzer Tool on most devices (Galaxy Nexus running 4.2, Droid 4 running 4.0.4, and Droid 2 running 2.3.4) shows no trace of activity B, which is what I expected. But on Samsung S3 running 4.1.1, MAT shows activity B objects still around, due to paths to the following GC roots (weak/soft references excluded): Class Name | Shallow Heap | Retained Heap --

Android - Clearing Navigation Backstack

亡梦爱人 提交于 2019-12-02 06:04:47
问题 I have 4 pages. From page_1 > page_2 > page_3 > page_4. Once the user reaches page_3 and clicks a button, it navigates to page_4. Once the button is clicked, I want to clear all the navigation history so when the user goes back on page_4, the app quits rather than going back to page_3. I've tried: Intent intent = new Intent(this, page_4.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); But nothing happens. I can still go

Android - Clearing Navigation Backstack

谁说胖子不能爱 提交于 2019-12-02 00:31:21
I have 4 pages. From page_1 > page_2 > page_3 > page_4. Once the user reaches page_3 and clicks a button, it navigates to page_4. Once the button is clicked, I want to clear all the navigation history so when the user goes back on page_4, the app quits rather than going back to page_3. I've tried: Intent intent = new Intent(this, page_4.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); But nothing happens. I can still go back to page_3, page_2 etc. How do I make it so that when the user clicks on the button on page_3, he

White screen after going back through Fragments

戏子无情 提交于 2019-12-01 09:19:20
I've got an Android application which is working fine, but I've found an annoying bug which I don't know what else do to solve it. My application has a single Activity (call it HomeActivity; well, plus the Preferences Activity) and lots of Fragments. HomeActivity manages the replacement of every Fragment using this method (found in this thread and especially looking into the following comment ): public void switchFragment(Fragment pFragment, String pTagFragment){ String backStateName = pTagFragment; boolean fragmentPopped = mFragmentManager.popBackStackImmediate (backStateName, 0); if (

How to make fragment replaced by a specific fragment when back button pressed

♀尐吖头ヾ 提交于 2019-12-01 07:49:54
问题 I have an app that contain a navigation drawer one of the fragments is the home fragment I want the app when the back button pressed in some other fragments to go to the home fragment for example if the user pressed on fr1 then fr2 then fr3 I want it to return back to the home button (where fr1,2,3 are the fragments of the navigation drawer and notice that there is other fragments in the app I don't want them to go to the home when back button pressed) 回答1: If you have multiple fragments in

Use backstack with ViewPager

醉酒当歌 提交于 2019-11-30 20:01:15
I am using a ViewPager to implement swiping in my android app. However, I would like the previous fragment to be shown when the user uses the back button instead of ending the activity. Is there any way to do that? Thanks Sebastian Override the functionality of your Activity : public class Activity extends Activity { @Override public void onBackPressed() { // do stuff myFragment.onBackPressed(); } } public class Fragment extends Fragment { public void onBackPressed() { // do stuff } } I had a similar problem, this is how I solved it. I had a ViewPager with 6 fragments and wanted to keep track

Prevent The Same Fragment From Stacking More Than Once ( addToBackStack)

◇◆丶佛笑我妖孽 提交于 2019-11-30 19:53:17
I have an Activity with three Fragments lets call them A , B and C . Fragment A is called in the Activity onCreate() . FragmentA fragA = new FragmentA(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.activity2_layout, fragA, "A"); transaction.commit(); And gets replaced with Fragment B or C when certain buttons are pressed, and the FragmentTransaction calls addToBackStack() . FragmentB fragB = new FragmentB(); //or C FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.activity2_layout, fragB, "B"); //or C transaction

Android fragments navigation and backstack

纵然是瞬间 提交于 2019-11-30 19:40:19
I have a header bar (kinda like menu) and 4 fragments (MAIN, A, B, C) from which the MAIN should be 'main/root' fragment for backstack. Problem i have is when user via menu goes for example MAIN > A > B > C. If i simply use backstack it will go in reverse order which i don't want. I need back button to go back to MAIN no matter how user navigated to one of those 3. My current code (which is wrong, it quits app when not in MAIN and current fragment is switched from other non-MAIN fragment) looks like this: private void SwitchFragment(Fragment pFragment) { FragmentTransaction ft =

Why Behaviours are different ?- android:launchMode=“singleTask” , android:taskAffinity=“” And Intent.FLAG_ACTIVITY_NEW_TASK

[亡魂溺海] 提交于 2019-11-30 15:14:52
I have Four Activity - A,B,C,D I am calling these four activity in manner --> A-B-C-D-B. (Specified Manner) I have three scenario. 1st :- I am defining android:launchMode="singleTask" only in B Activity. And I am calling all activity via Intent in above specified manner. Now First calling A-B-C-D , BackStack Task 1 : A-B-C-D, Now I again call B, Then BackStack Task 1 : A-B . Here C and D Activities are destroyed. 2nd :- I am defining android:launchMode="singleTask" & android:taskAffinity="" in B Activity. And I am calling all activity via Intent in above specified manner. Now First calling A-B

Use backstack with ViewPager

萝らか妹 提交于 2019-11-30 15:08:08
问题 I am using a ViewPager to implement swiping in my android app. However, I would like the previous fragment to be shown when the user uses the back button instead of ending the activity. Is there any way to do that? Thanks Sebastian 回答1: Override the functionality of your Activity : public class Activity extends Activity { @Override public void onBackPressed() { // do stuff myFragment.onBackPressed(); } } public class Fragment extends Fragment { public void onBackPressed() { // do stuff } }