I have created two activities namely MainActivity and registration. MainActivity is used for logging in, where the user enters his name and password. MainActivity has three buttons
- Login Button
- Register Button
- Exit Button.
When I press the login button the user will be logged into his account using the username and password which he has entered. Clicking on register button will navigate into the registration activity. The registration activty has a back button to navigate back into the mainactivity. I have the third exit button in the mainactivity to exit from the application completely. I have created an instance of the exit button and in the setonclicklistener part of the exit button, I have written the following code.
Button exit=(Button)findViewById(R.id.exit);
exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);
}
});
Now when I run the application firstly, the mainactivity will be displayed. Upon clicking the register button, the registration activity is displayed. When I click on the back button in the registration activity, I will be moved to the mainactivity. Then from the mainactivity when I press the Exit button, The application closes and the home screen will displayed. When I open my application again once more, instead of seeing the mainactivity, I'm seeing the registration activity. Please help me out. I need to see the mainactivity when I click again my application icon instead of registration activity. Sorry for the so long question. Can anyone please help me out..
Add this Tag in the Android Manifest.xml file inside the MainActivity