2016-08-24 82 views
0

已經看到了很多的前和嘗試,但沒用,我在這裏的代碼Android-如何啓動活動啓動結束後

AndroidManifest

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="tao800.tuan800.com.teststart" 
      android:installLocation="internalOnly"> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 
    <application 
     android:name=".MyApplication" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 
     <receiver 
      android:name=".receiver.BootBroadcastReceiver" 
      android:enabled="true"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED"/> 
       <action android:name="android.intent.action.BOOT_COMPLETED123"/> 
<category android:name="android.intent.category.DEFAULT"/> 
      </intent-filter> 
     </receiver> 
     <activity android:name=".Main2Activity"> 
     </activity> 
    </application> 
</manifest> 

BootBroadcastReceiver

public class BootBroadcastReceiver extends BroadcastReceiver{ 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d("myservice","get boot complete action"); 
     Intent intent2 = new Intent(context,Main2Activity.class); 
     intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     context.startActivity(intent2); 
    } 
} 

有人能告訴我如何解決這個問題嗎?

ps:它在genymotion上正常工作,但不能在我的android手機上工作。

+0

是Android版本和API的版本一樣在你的genymotion和電話清單? –

+1

''標籤之外的'<使用權限>'是不是?裏面有''嗎?在重新啓動之前,您是否在安裝後至少運行過一次「活動」? –

+0

我猜測,這是一段錯誤的代碼 - 「' – CodeWalker

回答

0

確保您的應用是在有權自行啓動開機後