If it is possible to send a signal to kill an activity on a device using the same app from another device. Similar to a notification and when notification is clicked it opens an activity but in this case I would like to know if it is possible to close an activity without clicking the notification or something of the sort (Should all be done automatically as soon as the app, say receives a notification).
Is it possible to kill an activity using another device running the same app using Push Notification
Asked
Active
Viewed 59 times
0
-
[This thread](https://stackoverflow.com/questions/31800316/how-can-i-kill-a-remote-process-for-my-app) might be of help – Vishal Nov 24 '19 at 06:56
-
do you want to close a particular device's app ? – Jacks Nov 24 '19 at 07:02
-
Nope, just an activity or have the app return to MainActivity with out having any click interactions, just done autonomously as soon as the app, say receives a notification – maltez kolt Nov 24 '19 at 07:57
1 Answers
0
Send notification to the device you want to close it's activity and then use interface callback or eventbus to close the activity
here you can check if activity is active
boolean active;
@Override
public void onStart() {
super.onStart();
active = true;
}
@Override
public void onStop() {
super.onStop();
active = false;
}
Using eventbus
EventBus.getDefault().post(new MessageEvent());
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(closeActivityEvent event) {
if (active)
this.finish();
}
}
Using interface
activityInterface.closeActivity();
@Override
public void closeActivity() {
if(active){
this.finish();
}
}

Ahmad Salman
- 143
- 2
- 9
-
sending notification would mean the notification would have to be clicked to close the activity right; – maltez kolt Nov 24 '19 at 07:54
-
am looking for a solution to do it with out any interaction of sorts from the user – maltez kolt Nov 24 '19 at 07:54
-
you don't need any interaction from user. when you receiving notification onMessageReceived() method is called then you can use eventbus or interface action to finish the activity – Ahmad Salman Nov 24 '19 at 08:01