How to finish all activities in your Android application through simple call

Published by Igor Khrupin on


Maybe you had some problem which i can discribe and show the way to fix it.

Actually, problem is a closing all your Android application’s Activities through simple call.

There are many ways to fix this. I want to show you one of them.

Before starting i want to ask you something. Please email me or post a comment for this post if you find better and more flexible way to close all Android application’s activities. I will be appreciative you!!

Below you can download the sample project. This project contains 3 (three) activities and ONE abstract Activity. All Activities in this sample project extended this abstract Activity class. This Activity extended Activity class from Android API.

The most interesting contains in this abstract Activity. Here the source:

package com.hrupin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public abstract class AppBaseActivity extends Activity {
	private BaseActivityReceiver baseActivityReceiver = new BaseActivityReceiver();
	public static final IntentFilter INTENT_FILTER = createIntentFilter();
	private static IntentFilter createIntentFilter(){
		IntentFilter filter = new IntentFilter();
		return filter;
	protected void registerBaseActivityReceiver() {
		registerReceiver(baseActivityReceiver, INTENT_FILTER);
	protected void unRegisterBaseActivityReceiver() {
	public class BaseActivityReceiver extends BroadcastReceiver{
		public void onReceive(Context context, Intent intent) {
	protected void closeAllActivities(){

You can see that this class contains BrodcastReceiver –> BaseActivityReceiver

This broadcastReceiver makes finish() Activity. This class also contains methods to create intentFilter, register/unregister broadcastReceiver and method closeAllActivities() which broadcast Intent to close Activities of only YOUR Android apllication.

The code is pretty simple. ๐Ÿ™‚
Here you can download the sample project

Download it from github


karensilkwood · 1 March, 2012 at 17:48

This is just gorgeous code!! Fitted nicely into my ActivityBase! ๐Ÿ™‚

marek · 16 April, 2012 at 21:59

thanks for the code ๐Ÿ™‚

Koti · 9 June, 2012 at 14:57

Nice,My issue solved thank you

Cyol · 25 July, 2012 at 21:36

At last after a lot of searching for finish all my activities, it’s simple and elegant !

Thank you

Cyol · 25 July, 2012 at 21:39

Can i Translate this in french on my blog ? (with a link to here and your name of course)

Igor · 27 July, 2012 at 21:32

Hello Cyol,
Course you can.

mano · 29 January, 2014 at 07:38

Application closed caused by-illegalArgumentException:Receiver not registered(unRegisteredBaseActivityReceiver)

mano · 29 January, 2014 at 08:17

Thanks for your code dude:) Now My Application working good…

varshit · 8 November, 2014 at 08:43

Thank you very much ๐Ÿ™‚
This example is very helpful for me

Thanks One again ๐Ÿ™‚

varshit · 8 November, 2014 at 08:44

Thank you very much ๐Ÿ™‚
This example is very helpful for me

Thanks One again ๐Ÿ™‚

amier · 20 November, 2014 at 21:44

thank you very much ๐Ÿ™‚
your code is very helpful for me. ๐Ÿ™‚

Kesava Reddy · 15 March, 2016 at 06:56

Thank You very much.

The code is awesome..!

Peter Phyo · 24 March, 2017 at 07:07


dev nunu · 27 April, 2019 at 14:57

You saved my life. Thank you so much!

Leave a Reply to amier Cancel reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.