2つのアプリケーションがあります。最初のアプリケーションのユーザーは、彼ができる行動の2つのオプションがあるダイアログを開くことができます。これは次のように行われる:2つのアプリケーション間でインテントを連続的に処理する
public void sendSms(String number)
{
Intent myIntent = new Intent(Intent.ACTION_SENDTO);
myIntent.setData(Uri.parse("smsto:" + number);
startActivity(myIntent);
}
public void call(String number)
{
Intent myIntent = new Intent(Intent.ACTION_CALL);
myIntent.setData(Uri.parse("tel:" + number);
startActivity(myIntent);
}
第二アプリはインテントフィルタを有しており、それはこのアクションを識別する:
<activity android:name="com.my.path.MyActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.CALL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="smsto" />
</intent-filter>
<intent-filter android:priority="100" >
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
</activity>
第二のアプリケーションがこのようなインテントを処理する:
protected void onNewIntent(Intent inten)
{
super.onNewIntent(intent);
String action = intent.getAction();
if(action.equals(Intent.ACTION_CALL))
{
*here make a fragment transaction to the fragment which handles calls *
}
else if(action.equals(Intent.ACTION_SENDTO))
{
*here make a fragment transaction to the fragment which handles sms*
}
}
ユーザーが最初のアプリケーションを開き、アクションの1つを選択すると、それは正常に機能し、戻るボタンを押すと、彼は最初のアプリケーションに戻ります。彼が最初のアプリケーションに戻ったとき、ダイアログはまだアクションをしたときのように開いています。
問題は、ユーザーが2番目のアプリケーションを呼び出すためにコールアクションを再度押すと、2番目のアプリケーションがフォアグラウンドになりますが、onNewIntent
が再び呼び出されたように見えないため、フラグメントトランザクションは起こる。
次に、2回目にonCreate
メソッドが呼び出されたので、そこにインテントを処理しようとしました。 SENDTOアクションでは機能しましたが、CALLアクションでは機能しませんでした。 CALLアクションでは、onCreateインテント処理が呼び出されていますが、何らかの理由でフラグメントトランザクションが機能しません(SENDTOアクションのフラグメントトランザクションが機能します)。
同じアクションを再度実行しようとすると、onNewIntent
メソッドが呼び出されないのはなぜですか?そして、コール・アクションのためにトランザクションが機能しないのはなぜですか?
UPDATE:フラグメントトランザクションは、今すぐonCreateメソッドで機能します。しかし、私はまだすべてを処理することを好むだろうonNewIntent
あなたは 'finish()'を呼び出していますか?アプリがクラッシュしているかどうかをlogcatで調べましたか? Androidは 'Activity'の新しいインスタンスを作成した場合にのみonCreate()を呼び出します。すでにインスタンスがアクティブ(生きている)の場合、Androidは新しいインスタンスを作成しません。 –
アプリはクラッシュせず、私はfinish()を呼び出しません。アプリは、もう一方がインテントを送信するまで、バックグラウンドにあります。 –