Kamalone
Kamalone

Reputation: 4115

Destroying Activity or application itself from another application

I have two applications. One is a receiver and its starting my application. It works fine. Now i want destroy my application from the receiver itself. Is that possible ? Please note that these are my own application

Upvotes: 1

Views: 74

Answers (2)

DroidBender
DroidBender

Reputation: 7892

It is possible but the activity has to finish itself using the finish()-method.

You can register an activity to a receiver using registerReceiver(..) and handle your logic in your activity. Don't forget to unregisterReceiver(...) inside the OnDestroy.

Example:

BroadcastReceiver mReceiver;

@Overrride
public void onCreate(Bundle savedInstanceState){

  IntentFilter filter = new IntentFilter();
  filter.addAction(...);

  mReceiver= new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
      // implement logic
      finish();
    }
  }
  registerReceiver(mReceiver, filter);

}

Upvotes: 2

Vinay W
Vinay W

Reputation: 10190

you cant directly control the lifecycle of one activity from another actvity alternates to this could be :

  • you can set a timer in the new activity, if you want to end it after a certain amount of time, and call finish()' inrun()`
  • you can finish() the new activity on some events with EventListeners

Upvotes: 0

Related Questions