-1

3 つのレイアウトを持つアプリケーションがあります。

Android のドキュメントによるとFLAG_ACTIVITY_CLEAR_TOP、インテントでフラグを使用して最上位のアクティビティに戻り、アクティビティの起動モードが「標準」に設定されている場合、アクティビティの新しいインスタンスを取得する必要があります。これにより、環境設定で設定された別のレイアウトが読み込まれます。

以外のフラグを使用せずに、4.2.2 を実行している Android エミュレーターでこの動作が発生しますFLAG_ACTIVITY_CLEAR_TOP。4.2.2 も実行している Nexus 7 では、アプリを終了して再起動しない限り、新しいインスタンスを取得することはなく、古いレイアウトを取得することはありません。

マニフェストに 'android:launchMode="standard"' を追加FLAG_ACTIVITY_NEW_TASKし、インテントにフラグを変更せずに追加しようとしました。

マニフェストからの抜粋と、それを再起動する必要があるコード スニペットを次に示します。

<activity
android:name="org.billthefarmer.accordion.MainActivity"
android:label="@string/app_name"
android:launchMode="standard"
android:screenOrientation="portrait" >
  <intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

クラスからのコード:

case android.R.id.home:
    // app icon in action bar clicked; go home
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    return true;

これを達成するためのより良い方法はありますか、それとも何か不足していますか?

4

1 に答える 1

0

このメソッドをアクティビティ コードに追加してみてください。

public void reload() {

    Intent intent = getIntent();
    overridePendingTransition(0, 0);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    finish();

    overridePendingTransition(0, 0);
    startActivity(intent);
}

ここから撮影

于 2013-05-23T12:45:49.613 に答える