如何在手机重启时自动重启Android应用程序。我为android做了一个应用程序,现在我希望它能在手机重新启动时自动重新启动,有人能帮我一下吗。?
您可以使用BroadcastReceiver来侦听BOOT_COMPLETED广播并执行您想要的操作。
<receiver android:name=".BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
来源http://www.anddev.org/launch_activity_on_system-emulator_startup-t428.html
清单
<receiver class=".MyStartupIntentReceiver">
<intent-filter>
<action android:value="android.intent.action.BOOT_COMPLETED" />
<category android:value="android.intent.category.HOME" />
</intent-filter>
</receiver>
MyStartupIntentReceiver类:
public class MyStartupIntentReceiver extends IntentReceiver {
@Override
public void onReceiveIntent(Context context, Intent intent) {
/* Create intent which will finally start the Main-Activity. */
Intent myStarterIntent = new Intent(context, LaunchOnStartup.class);
/* Set the Launch-Flag to the Intent. */
myStarterIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
/* Send the Intent to the OS. */
context.startActivity(myStarterIntent);
}
}