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
...但服务不启动,我不知道问题
请帮帮我!
有没有错误,但是当我看paramte我没有找到我的srvice开始 – user2326926 2013-05-01 21:36:50
所以继承人一个解决方案,我认为如此.....你只有一个服务在你的包裹,所以当你的包安装没有人实际上有星级t服务,所以通过adb开始它是你唯一的选择,那么你将能够在手机设置>应用程序/运行中看到该服务............不要在包名称中使用/ hv上面使用...尝试只是这个adb外壳我startservice com.example.servicesusb.UsbService 而不是com.example.servicesusb/.UsbService – cafebabe1991 2013-05-02 06:02:46