Android 从其他应用更改服务中的变量
Android Change a variable in service from other app
标题说明了一切,我需要从我的其他应用程序中的 activity 更改我的服务变量,是否最终确定服务,这可能吗?
找到消息object,但不太明白
最简单的解决方案是实施 BroadcastReceiver。您的服务侦听广播,而另一个应用程序发送广播。
示例接收者:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Get bundle from intent and use it to set your Variable in your Service
}
}
广播公司示例 (courtesy of Vogella):
Intent intent = new Intent();
intent.setAction("de.vogella.android.mybroadcast");
sendBroadcast(intent);
标题说明了一切,我需要从我的其他应用程序中的 activity 更改我的服务变量,是否最终确定服务,这可能吗?
找到消息object,但不太明白
最简单的解决方案是实施 BroadcastReceiver。您的服务侦听广播,而另一个应用程序发送广播。
示例接收者:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Get bundle from intent and use it to set your Variable in your Service
}
}
广播公司示例 (courtesy of Vogella):
Intent intent = new Intent();
intent.setAction("de.vogella.android.mybroadcast");
sendBroadcast(intent);