2016-08-11 8 views
1

最近使用したアプリの一覧から活動を開きます選択して共有オプションが選択されている、私のアプリが一覧表示され、活動の新しいインスタンスがあるとき、意向私はonDestroyを(呼び出すたびに作成)と私は起動モード<strong>singleTask</strong>でアプリを作成し、テキストがあるときに他のアプリからので、</strong><strong>text/plainのMIMEタイプのインテントフィルタを持つ

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    Intent intent = getIntent(); 
    String action = intent.getAction(); 
    String type = intent.getType(); 

    if (intent.ACTION_SEND.equals(action) && type != null) { 
    sharedData = FileHandler.handleSendText(intent); 
    } 
} 

@Override 
protected void onNewIntent(Intent intent) { 
    String action = intent.getAction(); 
    String type = intent.getType(); 

    if (intent.ACTION_SEND.equals(action) && type != null) { 
     sharedData = FileHandler.handleSendText(intent); 
    } 

    super.onNewIntent(intent); 
} 

@Override 
protected void onDestroy() { 
    if (android.os.Build.VERSION.SDK_INT >= 21) { 
     finishAndRemoveTask(); 
    } else { 
     finish(); 
    } 

    super.onDestroy(); 
} 

私はアプリで奇妙な挙動を有する午前に従うようのonCreateonNewIntent方法で着信コンテンツを扱います作成された入力テキストは、 sharedData可変スルーのonCreate方法及びアプリonDestroy方法は、(ボタンをバック押す)と呼ばれ、最近使用したアプリのアクティビティを開始したとき、のonCreate方法は正常であるが、これと呼ばれるIntent.getAction()Intent.getType()も有効な値を返しています。なぜそれが起こっているのですか?

答えて

0

これは、あなたが「最近のタスク」リストからアプリケーションを選択すると、それは元々のアプリケーションを起動するために使用されたのと同じIntentと、そのアプリケーションを起動します。あなたには

:-(設計により、残念ながら、あります場合は、IntentにSEND ACTIONが付きます

これを修正するには、「最近のタスク」リストからアプリが起動されたかどうかを確認し、それに応じて行動する必要があります(ACTIONを無視してください):

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    Intent intent = getIntent(); 
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { 
     // The activity was launched from history 
    } else { 
     String action = intent.getAction(); 
     String type = intent.getType(); 
     if (intent.ACTION_SEND.equals(action) && type != null) { 
      sharedData = FileHandler.handleSendText(intent); 
     } 
    } 
} 
+0

アフト私はインテントを取得し、アプリの場合、画面の向きを縦長から横長に変更すると、その逆もあります。** onCreate **メソッドが呼び出されるため、その場合** Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY **は0または1を返しますか? – TejaReddy

+0

オリエンテーションの変更後に 'onCreate()'で取得した 'Intent'は、オリエンテーションが変更される前に' onCreate() 'で取得した' Intent'とまったく同じです。 –

+0

また、** onDestroy **メソッドのrecentsからアクティビティをプログラムで除外し、** onCreate **メソッドのrecentsに再度含めるので、これはインテントフラグに影響しますか?ありがとう。 – TejaReddy

関連する問題

 関連する問題