0

わかりました、これは奇妙です。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 が呼び出されるまでに多くの時間がかかります。そして今、その理由は何ですか?

4

2 に答える 2

1

本当の問題 (もう一度開始するのに 10 秒) に集中するのではなく、間違った問題 (アクティビティを殺す) に集中していると思います。

まず、ホーム キーで他のアクティビティを終了した場合に、開くのに 10 秒かかる理由を理解する必要があります。

詳細を(ソースコード付きで)投稿していただければ、理解しやすく、役に立ちました。

于 2013-05-26T12:23:23.240 に答える
0

アプリを閉じたいときは、finish() を呼び出します。両方のアクティビティで finish() を呼び出し、クリックを処理するためにポップアップ ウィンドウに注意してください。

于 2013-05-26T09:58:02.807 に答える