2016-04-07 34 views
0

請解釋我爲什麼沒有Log?我想知道緊急撥號器是打開還是關閉。我試過這段代碼,但沒有發生任何事情。找出系統應用程序是否正在運行

public class MyService2 extends Service { 
    public MyService2() { 
    } 

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

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); 
     List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses(); 
     for(int i = 0; i < procInfos.size(); i++){ 
      if(procInfos.get(i).processName.equals("com.android.phone.EmergencyDialer.DIAL")) 
      { 
       Log.i("Result", "App is running - Doesn't need to reload"); 
      } 
     } 
    } 
} 

我怎麼稱呼緊急撥號器和我的服務:

Intent intent = new Intent("com.android.phone.EmergencyDialer.DIAL"); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent); 
       Intent intent1 = new Intent(MyService.this,MyService2.class); 
       startService(intent1); 

回答

0

請另外重寫3個功能:

public void onCreate() 
{ 
    Log.i(TAG, "Service onCreate--->"); 
    super.onCreate(); 
} 

@Override 
public void onStart(Intent intent, int startId) 
{ 
    Log.i(TAG, "Service onStart--->"); 
    super.onStart(intent, startId); 
} 

@Override 
public void onDestroy() 
{ 
    Log.i(TAG, "Service onDestroy--->"); 
    super.onDestroy(); 
} 
+0

對於我應該怎麼辦呢?請解釋 –

相關問題