【发布时间】:2016-10-28 21:49:57
【问题描述】:
我对安卓有点陌生。我想知道如何与前台启动的服务进行通信。
所以,我得到了一个带有通知的前台服务。 此通知有一个 (X) 按钮来停止服务。
服务有一个静态广播接收器。
public static class NotificationStopButtonHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Close Clicked",Toast.LENGTH_SHORT).show();
Log.i(LOG_TAG, "In Closed");
// imposible to do context.stopForground(true) or
// to call any other private coded by me
}
}
所以我的问题是: BroadcastReceiver 是最好的方法吗? 如果是:我如何与服务通信以在广播接收器中调用 stopForeground?
提前感谢您的回复。
Same question like mien... 但我想知道广播接收器之外的其他解决方案。谢谢
【问题讨论】:
标签: android service foreground