相关疑难解决方法(0)

PendingIntent启动和停止服务

我试图与一个按钮一个简单的小工具,开始ServiceOnClickPendingIntent().我可以开始很好,但我无法找到一种方法来阻止它(我知道我可以用一个BroadcastReceiver或类似的东西,但我想避免硬编码).

这是我的代码:

        Intent intent = new Intent(context, myService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);

        if (!ismyserviceup(context)) {
            views.setOnClickPendingIntent(R.id.my_button, pendingIntent);
        } else {
            // i need to stop it!!!!
        }
Run Code Online (Sandbox Code Playgroud)

android android-widget android-service android-pendingintent

10
推荐指数
1
解决办法
1万
查看次数