わかりました、これは奇妙です。AppActivity と PopupActivity という 2 つのアクティビティがあります (2 つ以上ですが、問題ではありません)。AppActivity はメインのアプリケーション アクティビティであり、アプリの設定が含まれています。PopupActivity は、ユーザーが通知のボタンをクリックしたときに開かれるダイアログです (これは RemoteViews 通知です)。まあ、それは動作します。よく働く。ただし、ユーザーが戻るボタンをクリックして AppActivity を閉じた場合のみ。ホームをクリックすると、ボタンをクリックしてから数秒後に PopupActivity が開きます。ユーザーがホーム ボタンで PopupActivity を閉じると、同じことが起こります。通知のボタンをクリックしても、PopupActivity がすぐに開かれるわけではありませんが、バックグラウンドのどこかにまだ存在する以前のアクティビティを強制終了するには数秒かかります。
onStop メソッドと onPause メソッドで finish() を呼び出してみましたが、問題は解決しません。
編集:これが私が持っているコードです:
マニフェスト:
<activity
android:name="cc.lupine.quicksocial.AppActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize" android:noHistory="true" android:clearTaskOnLaunch="true" android:finishOnTaskLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="orientation|screenSize"
android:excludeFromRecents="true"
android:showOnLockScreen="false"
android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth"
android:name="cc.lupine.quicksocial.PopupActivity"
android:noHistory="true"
android:launchMode="singleInstance"
android:taskAffinity=""
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name="cc.lupine.quicksocial.ShareService"></service>
ShareService.java (ユーザーが通知のボタンをクリックしたときに呼び出される関数のみ):
public static void startSharing(Context ctx, int n) {
Log.d("sn", "startsharing called in shareservice");
if(n == 1 || n == 2)
{
Intent i = new Intent(ThisApplication.getAppContext(), PopupActivity.class);
i.putExtra("shareType", n);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|
Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP|
Intent.FLAG_ACTIVITY_CLEAR_TASK|
Intent.FLAG_FROM_BACKGROUND|
Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(i);
} else if(n == 3) {
// doesn't matter for now
}
}
PopupActivity.java (フラグメント):
public class PopupActivity extends Activity implements OnDataPass {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("sn", "oncreate called in popupactivity");
super.onCreate(savedInstanceState);
instanceOfPopupActivity = this;
setContentView(R.layout.activity_popup);
ShareFragment sfrag = new ShareFragment();
Bundle args = new Bundle();
Bundle extras = getIntent().getExtras();
try {
//doesn't matter
} catch(Exception e) { e.printStackTrace(); finish(); }
sfrag.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.contFragment, sfrag);
fragmentTransaction.commit();
}
@Override
public void onPause()
{
Log.d("sn", "onpause called in popupactivity");
finish();
super.onPause();
}
@Override
public void onStop() {
Log.d("sn", "onstop called in popupactivity");
super.onStop();
}
@Override
public void onDestroy()
{
Log.d("sn", "ondestroy called in popupactivity");
super.onDestroy();
}
}
初めてポップアップを開くと、次のようになります。
05-26 14:37:14.149: D/sn(7218): startsharing called in shareservice
05-26 14:37:14.179: D/sn(7218): oncreate called in popupactivity
しかし、ホームボタンでポップアップを閉じて、もう一度開こうとすると:
05-26 14:38:11.620: D/sn(7218): startsharing called in shareservice
05-26 14:38:14.103: D/sn(7218): oncreate called in popupactivity
onCreate が呼び出されるまでに多くの時間がかかります。そして今、その理由は何ですか?