【发布时间】:2012-01-27 07:09:45
【问题描述】:
我有一个简单的AutoStart 应用程序和TimerTask 实现,几乎可以在许多设备上正常工作。问题是它在Samsung Galaxy Y(2.3.6) 和DELL XCD35(2.2) 中不起作用。当设备启动时TimerTask 工作几秒钟然后关闭。我检查了Application->Manage Application,我看到应用程序已经处于Force Stop 状态。这意味着我的应用程序如何在几秒钟后停止。那么,这两个设备中weird behaviour 的原因是什么,如果有人有解决方案,请分享它。
下面是我的代码。
MyReceiver.java
public class MyReceiver extends BroadcastReceiver{
private Timer mTimer = new Timer();
@Override
public void onReceive(Context context, Intent arg1) {
Toast.makeText(context, "Device Booted", Toast.LENGTH_LONG).show();
Log.d("TAG","Device Booted");
mTimer.scheduleAtFixedRate(new MyTimerTask(), 2000,2000);
}
private class MyTimerTask extends TimerTask
{
@Override
public void run() {
Log.d("TAG","TimerTask executed....");
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.autostart.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
【问题讨论】:
-
啊!!!任何反对投票的理由?
-
一个有效的、格式良好的问题,不需要投反对票...
标签: android android-layout android-widget android-manifest