Skip to content

Instantly share code, notes, and snippets.

@baleen37
Last active December 19, 2015 10:53
Show Gist options
  • Select an option

  • Save baleen37/02decb17b96c42898173 to your computer and use it in GitHub Desktop.

Select an option

Save baleen37/02decb17b96c42898173 to your computer and use it in GitHub Desktop.
public final class KillReceiver extends BroadcastReceiver {
private Activity activity;
public static final String ACTION_KILL_ACTIVITY = "ACTION_KILL_ACTIVITY";
public KillReceiver(Activity activity) {
this.activity = activity;
if(activity == null) throw new NullPointException("activity == null");
}
@Override
public void onReceive(Context context, Intent intent) {
activity.finish();
}
public static Intent createIntent(Context context) {
return new Intent(context.getPackageName() + "." + ACTION_KILL_ACTIVITY);
}
public KillReceiver register() {
activity.registerReceiver(this, new IntentFilter(activity.getPackageName() + "." + ACTION_KILL_ACTIVITY));
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment