2016-05-03 7 views
1

「Activityコンテキストの外側からstartActivity()を呼び出すと、FLAG_ACTIVITY_NEW_TASKが必要です」「Activityコンテキストの外側からstartActivity()を呼び出すがFLAG_ACTIVITY_NEW_TASKが必要とする」起こっます。フォローは私の受信機コードが既に設定

public class LogoutReceiver extends BroadcastReceiver { 
public static final String LOGOUT_ACTION = "com.ss.ee.logout"; 
private Logger logger = new Logger(LogoutReceiver.class.getSimpleName(), true); 

@Override 
public void onReceive(Context context, Intent intent) { 

    Intent logoutIntent = new Intent(context, LoginActivity.class); 
    logoutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
    //logoutIntent.putExtra("logout", true); 
    context.startActivity(intent); 
} 

}

あなたはそれを見ることができますですが、私はすでにFLAG_ACTIVITY_NEW_TASKを設定しています。 別のことを指摘したい。私は仕事のスレッドで私のHTTPリクエストからbroadcastreceiverを送信します。このようなコードは、次のようになります。

Handler mDelivery = new Handler(Looper.getMainLooper()); 
mDelivery.post(new Runnable() { 
      @Override 
      public void run() { 
       MyAppApplication.getInstance().sendBroadcast(new Intent(LogoutReceiver.LOGOUT_ACTION)); 
      } 
     }); 

誰でも問題を解決できますか?どんな助けも素晴らしいです。

+0

runOnUIThreadを使用する必要があります。http://developer.android.com/intl/es/reference/android/app/Activity.html#runOnUiThread(java.lang.Runnable) – Devrim

答えて

0

この問題は申し訳ありません。私の間違いはこの問題を引き起こします。問題の点を見てください。

@Override 
public void onReceive(Context context, Intent intent) { 

Intent logoutIntent = new Intent(context, LoginActivity.class); 
logoutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
//logoutIntent.putExtra("logout", true); 
context.startActivity(intent);//Here should be logoutIntent 
} 

申し訳ありません。

関連する問題