2013-05-01 179 views
1

我開發了一個在後臺運行的應用程序,我用IntentService作爲開頭。在後臺運行應用程序IntentService

這是我的代碼:

public class UsbService extends IntentService { 
    /** 
     * A constructor is required, and must call the super IntentService(String) 
     * constructor with a name for the worker thread. 
     */ 
     public UsbService() { 

      super("UsbService"); 

     } 



     /** 
     * The IntentService calls this method from the default worker thread with 
     * the intent that started the service. When this method returns, IntentService 
     * stops the service, as appropriate. 
     */ 

     @Override 
     protected void onHandleIntent(Intent intent) { 
      Log.e("why", "fofo"); 
      Toast.makeText(getApplicationContext(), "starting", Toast.LENGTH_LONG).show(); 


    // mNotification.notify(132, builder.build()); 
      // Normally we would do some work here, like download a file. 
      // For our sample, we just sleep for 5 seconds. 
     /* long endTime = System.currentTimeMillis() + 5*1000; 
      while (System.currentTimeMillis() < endTime) { 
       synchronized (this) { 
        try { 
         wait(endTime - System.currentTimeMillis()); 
        } catch (Exception e) { 
        } 
       } 
      }*/ 
     } 
} 

清單

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.servicesusb" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="12" 
     android:targetSdkVersion="16" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app`enter code here`_name" 
     android:theme="@style/AppTheme" > 

     <service android:name=".UsbService" > 

      </service> 
    </application> 

</manifest> 

我要開始從亞行殼服務,所以我用這個命令

am startservice -n com.example.servicesusb/.UsbService 

...但服務不啓動,我不知道問題

請幫幫我!

回答

0

如果那麼你的服務存在就可以按以下

亞行外殼上午startservice <packageofservice>

如果仍然無法正常工作嘗試張貼你運行此命令後,您收到的錯誤開始

+0

有沒有錯誤,但是當我看paramte我沒有找到我的srvice開始 – user2326926 2013-05-01 21:36:50

+0

所以繼承人一個解決方案,我認爲如此.....你只有一個服務在你的包裹,所以當你的包安裝沒有人實際上有星級t服務,所以通過adb開始它是你唯一的選擇,那麼你將能夠在手機設置>應用程序/運行中看到該服務............不要在包名稱中使用/ hv上面使用...嘗試只是這個adb外殼我startservice com.example.servicesusb.UsbService 而不是com.example.servicesusb/.UsbService – cafebabe1991 2013-05-02 06:02:46

相關問題