2012-08-22 75 views
1

如何讓Android應用程序在手機重啓時自動重啓。 我做了一個android的應用程序,現在我想它會重新啓動時自動重新啓動 ,任何人都可以請幫我這個。?如何讓Android應用程序在手機重啓時自動重啓

+0

您可以檢查出的問題,並在此[文章](HTTP回答:// stackoverflow.com/questions/6391902/how-to-start-an-application-on-startup) – DroidBender

回答

0

您可以使用BroadcastReceiver來監聽BOOT_COMPLETED廣播並執行您想要的操作。

+0

它究竟如何工作? – user1616773

0
<receiver android:name=".BootReceiver" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 
+0

可否請您解釋一下更多的地方在.java文件中使用此引導接收器 – user1616773

+0

創建 BootReceiver.java文件 此文件在BOOT_COMPLETED時自動運行。並在這個文件中你可以正確地重新啓動代碼 –

0

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); 

     } 

} 
相關問題