如何在Android中重启服务? [英] How to restart a service in android?
问题描述
有人知道如何在android中重新启动服务吗?我有一个在设备启动时调用的服务..还有一个用于保存配置的option.java.
has anyone know how to restarting a service in android?? i have a service that called when device is booting.. and i have an option.java for saving my configuration..
如果我在option.java中编辑配置,那么我必须重新启动服务才能生效.
if i editing a configuration in option.java, then i must restarting my service to takes the effect..
我只知道如何启动服务,并且在服务运行后,我不知道在进行新配置后如何重新启动它.
i only know how to start a service and after it running, i don't know how to restart it after a new configuration was made.. any idea??
startService(new Intent(this, ListenSMSservice.class));
推荐答案
在您的元素中
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2)在您的元素中(一定要为您的BroadcastReceiver使用完全限定的[或相对]类名称):
2) In your element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver):
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
public class MyBroadcastreceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, MyService.class);
context.startService(startServiceIntent);
}
}
更多详细说明:此
这篇关于如何在Android中重启服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!