我有一個簡單的AutoStart
應用程序與TimerTask
實現,這在幾乎很多設備上都能正常工作。問題在於它不在Samsung Galaxy Y(2.3.6)
和DELL XCD35(2.2)
中工作。當設備啓動TimerTask
工作幾秒鐘,然後關閉。我檢查了Application->Manage Application
,我看到Applcation已經在Force Stop
狀態。這意味着一些如何我的應用程序在幾秒鐘後停止。那麼,這兩個設備中的weird behaviour
的原因是什麼,如果任何人有解決方案,請分享它。AutoStart應用程序無法正常工作
以下是我的代碼。
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>
啊!任何關於投票的理由? – 2011-12-24 11:43:00
一個有效的,格式良好的問題,不需要反對投票... – WarrenFaith 2011-12-24 11:54:08