Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I try this,but it's stuck on Login.class not really close application..

Java
@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Take appropriate action for each action item click
		switch (item.getItemId()) {
		case R.id.action_settings2:
				Intent intent = new Intent(getApplicationContext(), Login.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			return true;
			
		case R.id.action_settings3:
			final AlertDialog.Builder adb = new AlertDialog.Builder(this);
			
			adb.setTitle("Confirm?");
			adb.setMessage("Plese Confirm");
			adb.setNegativeButton("Cancel", null);
			adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
				public void onClick(DialogInterface dialog, int arg1) {
					/*Intent intent2 = new Intent(Intent.ACTION_MAIN);
					intent2.addCategory(Intent.CATEGORY_HOME);
					intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					startActivity(intent2);*/
					
					Intent intent = new Intent(getApplicationContext(), Login.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					intent.putExtra("EXIT", true);
					startActivity(intent);
					
				}
			});
			adb.show();
			
			if (getIntent().getBooleanExtra("EXIT", false)) {
			    finish();
			}
			
			return true;
			
		default:
			return super.onOptionsItemSelected(item);
		}
	}


thank you :D
Posted
Updated 29-Sep-14 19:20pm
v2
Comments
Richard MacCutchan 30-Sep-14 3:54am    
Where is the code for the Login class?
David Crow 29-Jun-20 23:00pm    
What exactly does "stuck on Login.class" mean?

Are you working with action_settings2 or action_settings3?

if (getIntent().getBooleanExtra("EXIT", false))
{
    finish();
}

What is the purpose of this at the end of onOptionsItemSelected()?
Richard Deeming 1-Jul-21 7:57am    
Did you notice the date? I would hope the OP is not still waiting for an answer. :)

Also, did I notice the year on your comment? 🤦‍♂️

wild guess (i'm not into Android at all)

Java
getRuntime().exit();



There might be some additional to make the gc clean up. check it out in the Android Developers API:

http://developer.android.com/reference/java/lang/Runtime.html[^]

have fun!
 
Share this answer
 
Use this method:
C#
public static void KillApp(){
     System.runFinalization();
     System.exit(0);
}

Plus:
If your Android application runs on a Blackberry OS 10 use this method:
C#
public static void KillApp(){
        android.os.Process.killProcess(android.os.Process.myPid());
    }

Jorgesys
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900