1
私は時間を見つけ出すことができなかった問題を持って更新されていません: "fragment.onResume();" 私が使用した断片を示しながらonResumeとして は、私が活動内部断片を持っている、と時々私は以下のコードを持つフラグメントを呼び出し、</p> <p>を変数
newsFeedFragment fragment = new newsFeedFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.hide(getSupportFragmentManager().findFragmentById(R.id.fragment_container));
fragmentTransaction.hide(getSupportFragmentManager().findFragmentByTag("notifications_fragment"));
fragmentTransaction.show(getSupportFragmentManager().findFragmentByTag("news_feed_fragment"));
fragmentTransaction.addToBackStack(null);
fragment.onResume();
fragmentTransaction.commit();
は呼び出されません以下のコードで説明します。フラグメントが表示されると、onResumeが呼び出されます。しかし、私はonResumeメソッドの変数を更新しようとしますが、以下のコードでは更新されません。 onResumeが呼び出されると、ログの結果として「1」が表示されますが、毎回1ずつ増えることを期待していました。それを動作させる方法はありますか?あなたはonPauseおよびonResumeの場合、インスタンス変数に依存することはできません
int refreshNotificationVar = 0; //in the main class
@Override
public void onResume(){
super.onResume();
refreshNotificationVar = refreshNotificationVar + 1;
System.out.println(refreshNotificationVar);
}
http://stackoverflow.com/questions/36617328/singleton-method-gives-error-in-onresum-android/36619685#36619685こんにちはozo、私はシングルトンvarを使用しましたが、それを使用してエラーが発生しました、あなたはリンクを確認することがあります以下? – saner
シングルトンクラスを不適切に実装したと思います。基本的な例については、https://gist.github.com/Akayh/5566992をご覧ください。 – ozo
こんにちはozo、ありがとう、私の一日を救った、私はこれを数時間修正しようとしています:)あなたのリンクの方法が働いた。 – saner