How to Finish an Android Activity

Suppose you have two Activity

Activity A and Activity B

You want to navigate A to B and also want finish the previous Activity (in this case Activity A).
put this code inside your Activity A

A.this.finish(); // Activity_Name.this.finish(); 

So where you will put that line, well then you have to understand the life cycle of an Android Activity.

http://developer.android.com/reference/android/app/Activity.html

So i guess now you know, where you should put that line.

     @Override
	protected void onPause() {
		super.onPause();
		A.this.finish();
	}

Special case: If you just put it like this, with out any checking, than your app will not act like normally, because in screen rotation onPause() is also called. So as a result your app will finish when user rotates the screen.

     @Override
	protected void onPause() {
		super.onPause();
        // put some logic here 
		A.this.finish();
	}

enjoy 🙂

Well i edited the solution, it seems finishing the Activity in onStop() creates unknown bug like it calls the onDestroy() later, which creates serious bug in the code. So i move it to onPause() and its working great, thanks to Jamael Tanveer Vaia 🙂

Advertisements

Google Play New Developer Program Policy (“Content Policy”)

Google changes the Content Policy of Google play, have a look if you are an Android Developer, because if your app violates the new policy Google will remove your app from play store.

https://support.google.com/googleplay/android-developer/answer/3311168

The policy

http://play.google.com/about/developer-content-policy.html

Enjoy 🙂