バックグラウンドでサービスを実行しようとしています。私のアプリは、ユーザーがチェックボックスをオンにするとサービスが開始され、チェックが外されるとサービスが停止します。これは完全に正常に機能しています。しかし、問題は、タスクマネージャーからアプリを閉じると、サービスも停止することです。私が欲しいのは、タスクマネージャーから閉じた後もサービスを実行し続けることです。その場合、そのサービスを停止する唯一の方法は、ユーザー自身がボックスのチェックを外すことです。
どうすればこれを達成できますか?
これが私のコードです
私の主な活動
public class SampleServiceActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);
    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            if(isChecked) {
                Toast.makeText(getBaseContext(), "Checked", Toast.LENGTH_LONG).show();
                startService(new Intent(getBaseContext(), MyService.class));
            } else {
                Toast.makeText(getBaseContext(), "Unchecked", Toast.LENGTH_LONG).show();
                stopService(new Intent(getBaseContext(), MyService.class));
            }
        }
    });
}
}
私のサービスクラス
public class MyService extends Service {
Notify n = new Notify();
@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}
public int onStartCommand(Intent intent, int flags, int startId) {
    Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
    n.initNotification(getBaseContext(), true);
    return START_STICKY;
}
//method to stop service
public void onDestroy() {
    super.onDestroy();
    n.cancelNotification(getBaseContext());
    Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
}
}
アップデート
このサービスをgtalkサービスのように実行するにはどうすればよいですか?