[英]Is it possible to kill an activity using another device running the same app using Push Notification
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). 与通知类似,当单击通知时,它会打开一个活动,但在这种情况下,我想知道是否有可能在不单击通知或类似的东西的情况下关闭活动(应在应用程序完成后自动完成,例如收到通知)。
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()); EventBus.getDefault()。post(new MessageEvent());
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(closeActivityEvent event) {
if (active)
this.finish();
}
}
Using interface 使用界面
activityInterface.closeActivity(); activityInterface.closeActivity();
@Override
public void closeActivity() {
if(active){
this.finish();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.