9

そのため、アプリ全体に拡張された抽象クラスがあり、バックキーをオーバーライドして、アクティビティAを前に並べ替えます(フラグ付き)。

したがって、次のようになります。

A> B>どこでも、戻るキーでAに戻るはずです

FLAG_ACTIVITY_CLEAR_TOPを使用していますが、何らかの理由でAが完全に更新されているので、それは望ましくありません。

したがって、Flag_activity_clear_topはonResume()ではなくonCreate()をリロードしています。何が得られますか?

4

3 に答える 3

25

アクティビティを再起動せずに一番上に移動したい場合は、マニフェストでアクティビティのlaunchModeを singleTop に設定します。アクティビティが一番上に来ると、 onNewIntentへの呼び出しを受け取ります。onNewIntent は onResume の前に呼び出されます。特定のインテントに対してのみこの動作が必要な場合は、マニフェストの代わりにaddFlags呼び出しを使用してFLAG_ACTIVITY_SINGLE_TOP (FLAG_ACTIVITY_CLEAR_TOP に加えて) をインテントに追加できます。

于 2012-09-24T20:19:11.233 に答える
0

FLAG_ACTIVITY_CLEAR_TOPの API ドキュメントから

For example, consider a task consisting of the activities:
A, B, C, D. If D calls startActivity() with an Intent that
resolves to the component of activity B, then C and D 
will be finished and B receive the given Intent,
resulting in the stack now being: A, B.

**The currently running instance of activity B in the above example
will either receive the new intent you are starting here in its
onNewIntent() method, or be itself finished and restarted with the new intent.**

ですから、あなたの活動自体は終了し、再開されたと思います。

于 2012-09-25T17:43:08.540 に答える