HI @all,
I would like to have a Menu – Button, called Home, that goes back to
my root activity and removes all activities from the stack. Therefore,
if I press the back button afterwords, the application would close.
I tried calling the Activity with the intent flag
'FLAG_ACTIVITY_CLEAR_TOP' but it does not seem to work.
//
---------------------------------------------------------------------------
// Options Menu
/**
*
* The method <code>onCreateOptionsMenu</code>
*
* @param menu
* @return
* @overrides @see android.app.Activity#onCreateOptionsMenu
(android.view.Menu)
*/
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(0,1,1,"A");
menu.add(0,2,2,"B");
menu.add(0,3,3,"C");
menu.add(0,4,4,"HOME");
return super.onCreateOptionsMenu(menu);
}
/**
*
* The method <code>onOptionsItemSelected</code>
*
* @param item
* @return
* @overrides @see
* android.app.Activity#onOptionsItemSelected
(android.view.MenuItem
* )
*/
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case 1:
startActivity(new Intent(this,
TestActivityA.class));
break;
case 2:
startActivity(new Intent(this,
TestActivityB.class));
break;
case 3:
startActivity(new Intent(this,
TestActivityC.class));
break;
case 4:
Intent i = new Intent(this,
TestActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
break;
}
return super.onOptionsItemSelected(item);
}
// Options Menu
//
---------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---