Android 在后台IntentService中运行应用程序
我开发了一个在后台运行的应用程序,并使用了Android 在后台IntentService中运行应用程序,android,service,intentservice,Android,Service,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. *
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) {
}
}
}*/
}
}
。。。但是服务没有启动,我也不知道问题出在哪里
请帮帮我 如果您的服务存在,则可以按如下方式启动 亚行壳牌am startservice
如果仍然不起作用,请尝试在运行此命令后发布收到的错误没有错误,但当我在paramte中查看时,我没有发现我的设备已启动,因此我认为有一个解决方案……您的软件包中只有一个服务,因此安装软件包时,没有人实际启动该服务,因此,通过adb启动它是您唯一的选择,然后您将能够在电话设置>应用程序/运行中看到该服务………不要像上面所使用的那样在包名中使用/尝试此adb shell am startservice com.example.servicesub.UsbService而不是com.example.servicesub/.UsbService
<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