我從一個從服務獲取消息並顯示在對話框中的活動開始一個服務。當我點擊返回或主頁按鈕,應用程序被殺害。並且在多任務區域找不到應用程序。我沒有在onBackPressed()上編寫任何代碼。我該如何糾正這個問題?服務代碼。應用程序殺死onBackPressed android
public class BleepService extends Service{
String gotAlert;
Context context;
String drAlert=null;
public static boolean status = false;
public static final String TAG = BleepService.class.getSimpleName();
int counter = 0;
static final int UPDATE_INTERVAL = 5000;
private Timer timer = new Timer();
String resServer;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("SERVICE", "COMES TO THE ON STARTCOMMAND");
doRepeat();
//return super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
private void doRepeat() {
Log.i("SERVICE", "COMES TO THE DOREPEAT METHOD");
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
new GetStatus().execute();
}
}, 1000, UPDATE_INTERVAL);
}
class GetStatus extends AsyncTask<Void, Void, String>
{
@Override
protected String doInBackground(Void... params) {
ServiceHandler sh = new ServiceHandler();
resServer = sh.makeServiceCall(Urllist.urlGetPagerStatus, ServiceHandler.GET);
while(resServer.equals("1"))
{
status = true;
resServer = sh.makeServiceCall(Urllist.urlGetMsg, ServiceHandler.GET);
}
return resServer;
}
@Override
protected void onPostExecute(String result) {
Log.i("SERVICE", "COMES TO THE GetStatus AsyncTask Class");
super.onPostExecute(result);
if(!result.equals("0"))
{
Intent i = new Intent("com.bleep.DR_ALERT_MESSAGE");
i.putExtra("msg", result);
sendBroadcast(i);
}else{
Toast.makeText(getApplicationContext(), "No New Message", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onDestroy() {
//timer.cancel();
//super.onDestroy();
/*if (timer != null){
timer.cancel();
}*/
}
}
logCat?!!碼?!! – 2015-01-21 08:10:43