【问题标题】:stopService(intent) is not stopping service?stopService(intent) 没有停止服务?
【发布时间】:2014-05-15 10:01:45
【问题描述】:

这是我的问题的一些代码:

@Override
public void onDestroy() {
    Log.e("onDestroy------------->", "onDestroy called");
    Toast.makeText(this, " onDestroy Started", Toast.LENGTH_LONG).show();
    super.onDestroy();
}

b2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //startServiceManually();
            stopService(i);

        }
    });

【问题讨论】:

标签: android service


【解决方案1】:
try { 
stopService(new Intent(YOUR ACTIVITY NAME.this, YOUR SERVICE NAME.class));                                      
} catch (Exception e) {                                         e.printStackTrace();            
}

【讨论】:

    【解决方案2】:

    试试这个...

      Intent i = new Intent(this, THE_SERVICE_NAME.class);
      stopService(i);
    

    如果这不起作用,请确保您在服务中有一个 onDestroy,如果您在 onDestroy 中使用通知,请放置

     stopForeground(true);
    

    或者只是复制这个...

     @Override
     public void onDestroy(){
      super.onDestroy();
      stopForeground(true);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多