2013-03-25 80 views
0

我使用的是Android 3.2,我創建了我的Android應用程序,當我的平板電腦開始啓動完成時,它會自動啓動。Android啓動完成平板電腦啓動時的應用程序

一切正常,除了活動細運行兩次當應用程序被自動啓動(開機後完成)運行。

當我手動啓動應用程序時,不會引發此問題。

公共類BootStartUpApp擴展廣播接收器{

@Override 
public void onReceive(Context context, Intent intent) { 
    Intent startUpApps = new Intent(context, StartMainActivity.class); 
    startUpApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(startUpApps); 
} 

}

清單文件

我添加下面的代碼:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

<receiver android:name="com.logica.eHealthBox.tab.activity.BootStartUpApp" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </receiver> 
+2

有任何代碼向我們展示?。該廣播接收器部分將不勝感激。 – sebster 2013-03-25 07:38:35

回答

0

這裏是如何做到這一點:

public class BootReceiver extends BroadcastReceiver{ 
@Override 
public void onReceive(Context context, Intent intent) { 
     Intent i = new Intent(context, TestReceiversActivity.class); 
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(i); 
     } 
} 

在清單中輸入一個條目:

<receiver android:name=".BootReceiver" /> 

並且也有活動。

更多信息,請this linkthis link

+1

使用相同的代碼,在後,其工作正常,但我的問題是活動是運行兩次,當應用程序啓動後啓動完成 – 2013-03-25 09:36:13

+0

請張貼您的代碼和清單。 – 2013-03-25 10:54:21

相關問題