Tuesday, April 9, 2013

[android help] how to return to previous fragment activity

android - how to return to previous fragment activity - Stack Overflow



















Three fragment activities: MainFragmentActivity, Reports and ReportsType.


Reports is calling ReportsType.


There is a back button in ReportsType to go back with the following code:



public void goBackReport(View v)
{
finish(); // why MainFragmentActivity.java is called after finish()?
}


But its always returning to MainFragmentActivity.java. But it should be Reports.java.


























Try this..



Intent i=new Intent(this,MainFragmentActivity.class)
startActivity(i);
finish();

Intent i=new Intent(this,Reports.class)
startActivity(i);
finish();

Intent i=new Intent(this,ReportsType.class)
startActivity(i);
finish();


When you call new Activity write finish() in last























There's no concept of calling finish() on Fragment. Instead, you should keep stack of fragments when performing transactions. For example:



ft.addToBackStack(null); // ft is FragmentTransaction


So, when you press back-key, the current activity (which holds multiple fragments) will load previous fragment rather than finishing itself.




















default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...