back-stack

How to find back stack activities in an android application?

梦想的初衷 提交于 2019-11-30 11:29:44
问题 I have an application with activities back stack A -> B -> C -> D -> E. Now at activity E, I want to know the back stack activities that I navigated from. How do I find this?? 回答1: The code below can be used to extract all the tasks and the top activity within each task in the back stack ActivityManager m = (ActivityManager) ctx.getSystemService( ctx.ACTIVITY_SERVICE ); List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10); Iterator<RunningTaskInfo> itr = runningTaskInfoList

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

为君一笑 提交于 2019-11-30 03:56:58
问题 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 =

Back button closing app even when using FragmentTransaction.addToBackStack()

给你一囗甜甜゛ 提交于 2019-11-30 02:00:41
None of the other questions I have read on stackoverflow have been able to help with my problem. As far as I can tell, I am doing everything correctly. I have a master/detail flow with fragments. Upon creation of the main activity, the master fragment is loaded with the following code: Fragment frag; frag = new MainListFragment();//<-- **the master fragment** FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); transaction.replace(R.id.fragment_container, frag); Log.d("My Debug Bitches", "stack:" + fm.getBackStackEntryCount()); transaction.commit(

How to find back stack activities in an android application?

百般思念 提交于 2019-11-30 01:03:14
I have an application with activities back stack A -> B -> C -> D -> E. Now at activity E, I want to know the back stack activities that I navigated from. How do I find this?? The code below can be used to extract all the tasks and the top activity within each task in the back stack ActivityManager m = (ActivityManager) ctx.getSystemService( ctx.ACTIVITY_SERVICE ); List<RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10); Iterator<RunningTaskInfo> itr = runningTaskInfoList.iterator(); while(itr.hasNext()){ RunningTaskInfo runningTaskInfo = (RunningTaskInfo)itr.next(); int id =

Resume the Activity instead of Starting if already exists in back stack

这一生的挚爱 提交于 2019-11-29 23:54:45
I have an Activity_1 after a lot of steps, say Activity_2 > Activity_3 .... in some Activity_n I change some data related to Activity_1 and call it using Intent intent = new Intent(Activity_n.this, Activity_1.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); To refresh the content. But later I can go all the way back to Activity_1 where I started, which has old data. Instead I want the initial Activity_1 ' s onResume() to be called, using the above code. Or appropriate Flag FLAG_ACTIVITY_CLEAR_TOP consider a task consisting of the activities: A, B, C, D. If D

Fragment methods: attach(), detach(), remove(), replace(), popBackStack()

时光毁灭记忆、已成空白 提交于 2019-11-29 22:13:51
I am very confused between these functions and their purposes. What I have observed that using replace() replaces the existing fragment with a new one. We can use addToBackStack(null) to put that fragment in back stack so we can go back to the previously shown fragment. Now when a fragment is added (or replaced) - onAttach() -> onCreate() etc.... methods of the fragment are called in order. Now when we call remove() on the fragment from our activity, which functions of the fragment are called and in which order? What does attach() and detach() do? Does detach() remove the fragment? And when

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

我只是一个虾纸丫 提交于 2019-11-29 21:52:47
问题 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=""

onCreate always called if navigating back with intent

浪尽此生 提交于 2019-11-29 10:10:22
I have an activity called HomeActivity that has a SurfaceView and shows a camera preview picture. This activity is quiet heavy and feels slow if you are starting/restarting it. So I made some investigations and found out, that somehow always the onCreate method is being called. In my opinion this should not happen if the Activity has already been started? The documentation says : Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's

Clear Activity back stack [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-11-29 07:00:36
This question already has an answer here: Android: Clear the back stack 36 answers I start from activity A->B->C->D->E ..when i go from D->E there should be no activity in stack but, the user can use back button from D and go to C (without refreshing Activity C, like normal back function) You could add a BroadcastReceiver in all activities you want to close (A, B, C, D): public class MyActivity extends Activity { private FinishReceiver finishReceiver; private static final String ACTION_FINISH = "com.mypackage.MyActivity.ACTION_FINISH"; @Override protected void onCreate(Bundle

How to persist fragment data after backstack transactions?

旧时模样 提交于 2019-11-29 02:08:33
I've got an activity, containing fragment 'list', which upon clicking on one of its items will replace itself to a 'content' fragment. When the user uses the back button, he's brought to the 'list' fragment again. The problem is that the fragment is in its default state, no matter what I try to persist data. Facts: both fragments are created through public static TheFragment newInstance(Bundle args) , setArguments(args) and Bundle args = getArguments() both fragments are on the same level, which is directly inside a FrameLayout from the parent activity (that is, not nested fragments) I do not