简体   繁体   English

是否可以使用推送通知使用运行同一应用程序的其他设备终止活动

[英]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.

相关问题 应用程序使用解析在测试推送通知上崩溃 - App crashes on test push notification using parse 如何使用 appium 在 android 设备上关闭/终止应用程序? - How to close/kill an app on android device using appium? 如何通过Java服务器使用FCM向Android设备发送推送通知? - how to send push notification to the android device using FCM by java server? 如何通过java服务器使用GCM向Android设备发送推送通知? - how to send push notification to the android device using GCM by java server? 在Java中使用parse4j将推送通知发送到设备 - Sending Push Notification to device using parse4j in java 是否可以使用广播接收器在设备主屏幕上显示警报对话框,而不是在我们的应用程序主活动上? - Is it possible to display an alert dialog on the device home screen using a Broadcast Receiver , Not on our App main activity? 如何使用电话号码将通知从Android应用发送到另一个Android设备? - How to send a notification from an android app to another android device using phone number? 使用气氛推送通知 - Push notification using atmosphere 有没有一种方法可以在使用GCM接收推送通知时调试应用程序? - Is there a way to debug the app on receiving push notification using GCM? 如何使用Java在Windows Phone应用中发送推送通知? - How to send a push notification in windows phone app using java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM