back-stack

get the latest fragment in backstack

試著忘記壹切 提交于 2019-11-26 10:18:00
问题 How can I get the latest fragment instance added in backstack (if I do not know the fragment tag & id)? FragmentManager fragManager = activity.getSupportFragmentManager(); FragmentTransaction fragTransacion = fragMgr.beginTransaction(); /****After add , replace fragments (some of the fragments are add to backstack , some are not)***/ //HERE, How can I get the latest added fragment from backstack ?? 回答1: You can use the getName() method of FragmentManager.BackStackEntry which was introduced in

Android: open activity without save into the stack

白昼怎懂夜的黑 提交于 2019-11-26 08:14:01
问题 I have 2 activities: Main and List. From Main you can open List; from List you can open Main. I\'d like it so that every opening of List does not get saved into the \'history\'. So, pressing back from Main cannot return to List. Is it possible? 回答1: When starting your list's Activity , set its Intent flags like so: Intent i = new Intent(...); // Your list's Intent i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); // Adds the FLAG_ACTIVITY_NO_HISTORY flag startActivity(i); The FLAG

Android: Fragments backStack

我是研究僧i 提交于 2019-11-26 06:07:11
问题 Im trying to load an new fragment when a method is called. This method creates a new fragment and \"replaces\" the other fragment: private void showTestFragment(Fragment oldFragment, boolean addBackStack, BaseAdapter adapter, int position) { Cursor cursor = (Cursor)adapter.getItem(position); if(cursor != null){ int idx = cursor.getColumnIndexOrThrow(Episode._ID); long rowId = cursor.getLong(idx); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction =

How to prevent multiple instances of an Activity when it is launched with different Intents

别等时光非礼了梦想. 提交于 2019-11-26 05:51:24
I've come across a bug in my application when it is launched using the "Open" button on the Google Play Store app (previously called Android Market). It seems that launching it from the Play Store uses a different Intent than launching it from the phone's application menu of icons. This is leading to multiple copies of the same Activity being launched, which are conflicting with each other. For example, if my app consists of the Activities A-B-C, then this issue can lead to a stack of A-B-C-A. I tried using android:launchMode="singleTask" on all the Activities to fix this problem, but it has

Android - save/restore fragment state

一个人想着一个人 提交于 2019-11-26 05:25:41
问题 I have an Activity in which I go through several fragments. In every fragment I have several views ( EditText, ListView, Map , etc). How can I save the instance of the fragment that is shown at that moment? I need it to work when the activity is onPause() --> onResume() . Also I need it to work when I return from another fragment (pop from backstack). From the main Activity I call the first fragment, then from the the fragment I call the next one. Code for my Activity: public class Activity

Android: Remove all the previous activities from the back stack

我的未来我决定 提交于 2019-11-26 05:16:08
问题 When i am clicking on Logout button in my Profile Activity i want to take user to Login page, where he needs to use new credentials. Hence i used this code: Intent intent = new Intent(ProfileActivity.this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); in the onButtonClick of the Logout button. But the problem is when i click device back button on the Login Activity it takes me to the

Fragment onResume() & onPause() is not called on backstack

你说的曾经没有我的故事 提交于 2019-11-26 04:36:47
问题 I have multiple fragment inside an activity. On a button click I am starting a new fragment, adding it to backstack. I naturally expected the onPause() method of current Fragment and onResume() of new Fragment to be called. Well it is not happening. LoginFragment.java public class LoginFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.login_fragment, container,

Fragments onResume from back stack

旧巷老猫 提交于 2019-11-26 04:08:45
问题 I\'m using the compatibility package to use Fragments with Android 2.2. When using fragments, and adding transitions between them to the backstack, I\'d like to achieve the same behavior of onResume of an activity, i.e., whenever a fragment is brought to \"foreground\" (visible to the user) after poping out of the backstack, I\'d like some kind of callback to be activated within the fragment (to perform certain changes on a shared UI resource, for instance). I saw that there is no built in

Problems with Android Fragment back stack

点点圈 提交于 2019-11-26 03:29:04
问题 I\'ve got a massive problem with the way the android fragment backstack seems to work and would be most grateful for any help that is offered. Imagine you have 3 Fragments [1] [2] [3] I want the user to be able to navigate [1] > [2] > [3] but on the way back (pressing back button) [3] > [1] . As I would have imagined this would be accomplished by not calling addToBackStack(..) when creating the transaction that brings fragment [2] into the fragment holder defined in XML. The reality of this

Programmatically go back to the previous fragment in the backstack

一笑奈何 提交于 2019-11-26 03:26:12
问题 Say I have an activity that has fragments added programmatically: private void animateToFragment(Fragment newFragment, String tag) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container, newFragment, tag); ft.addToBackStack(null); ft.commit(); } What is the best way to return to the previous fragment that was visible? I found Trigger back-button functionality on button click in Android but I\'m thinking simulating a back key event isn\'t the