PIPI0 2016-01-23 23:16 采纳率: 85.7%
浏览 1531
已采纳

请问在服务中是否无法关闭服务呢???

public class MyService extends Service {

    private MyReceiver receiver;


    private class MyReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            onDestroy();
        }
    }  

    public void onCreate() {
        super.onCreate();
        Toast.makeText(MyService.this, "服务已启动", Toast.LENGTH_SHORT).show();
    }

    public int onStartCommand(Intent intent, int flags, int startId) {
        receiver=new MyReceiver();
        IntentFilter filter=new IntentFilter();
        filter.addAction("net.s5c.Changelink.wifiOff");
        registerReceiver(receiver, filter);
        flags=START_STICKY;
        return super.onStartCommand(intent, flags, startId);
    }



 public void onDestroy() {
        Toast.makeText(this, "服务已关闭", Toast.LENGTH_LONG).show();//可以打印出这句,但看后台还是无法关闭服务!
        super.onDestroy();
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

}

收到广播后能看到输出的onDestroy()的内容,但看正在运行中服务还是继续运行着,这是怎么回事呢?

  • 写回答

2条回答

  • PIPI0 2016-01-24 14:15
    关注

    没有任何作用看了半天也没找到我需要的!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧