Hi,
Maybe you had some problem which I can describe 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.ravi;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class AppBaseActivity extends Activity {
public static final String FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION = "com.ravi.FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION";
private BaseActivityReceiver baseActivityReceiver = new BaseActivityReceiver();
public static final IntentFilter INTENT_FILTER = createIntentFilter();
private static IntentFilter createIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION);
return filter;
}
protected void registerBaseActivityReceiver() {
registerReceiver(baseActivityReceiver, INTENT_FILTER);
}
protected void unRegisterBaseActivityReceiver() {
unregisterReceiver(baseActivityReceiver);
}
public class BaseActivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION)) {
finish();
}
}
}
protected void closeAllActivities() {
sendBroadcast(new Intent(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION));
}
}
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 application.
The code is pretty simple. :)
Download source code. Here you can download the sample project
Maybe you had some problem which I can describe 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.ravi;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class AppBaseActivity extends Activity {
public static final String FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION = "com.ravi.FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION";
private BaseActivityReceiver baseActivityReceiver = new BaseActivityReceiver();
public static final IntentFilter INTENT_FILTER = createIntentFilter();
private static IntentFilter createIntentFilter() {
IntentFilter filter = new IntentFilter();
filter.addAction(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION);
return filter;
}
protected void registerBaseActivityReceiver() {
registerReceiver(baseActivityReceiver, INTENT_FILTER);
}
protected void unRegisterBaseActivityReceiver() {
unregisterReceiver(baseActivityReceiver);
}
public class BaseActivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION)) {
finish();
}
}
}
protected void closeAllActivities() {
sendBroadcast(new Intent(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION));
}
}
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 application.
The code is pretty simple. :)
Download source code. Here you can download the sample project
Nice Blog...Waiting for Next Update..
ReplyDeletemobile app development companies in chennai
mobile app development company in chennai
thanks for sharing a valuable information.
ReplyDeleteBest Software company in Chennai
app development in chennai