0

現在、それぞれフラグメントに結びついているタブがあり、最終的にどのタブをどのように表示するかを見ています。 enter image description here今、私がバックボタンを押した後(私は持っていないし、各タブのバックスタックを気にしないだろう) - 私はそのUIのパラダイムが嫌いです)、その後、アプリケーションスイッチャーを使用するか、ランチャーから再起動して、私のquestionRowsは消えてしまいました(彼らはリロードしません)。私はディスプレイを保存するために何かをonPauseに実装する必要がありますか?なぜonResumeはこれを世話しないのですか?BACKからアプリに戻った後にインターフェイスが再ロードされない

package com.davekelley.polling; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup.LayoutParams; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.ScrollView; 
import android.widget.TableLayout; 
import android.widget.TableRow; 
import android.widget.TextView; 
import android.support.v4.app.Fragment; 

public class EconFragment extends Fragment { 

    private ViewGroup container; 
    private TableLayout questionContainer; 
    private ScrollView scrollView; 
    private ViewGroup econFragment; 
    static int pos = 0; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     Log.d("Econ", "onCreateView"); 
     this.container = container; 
     return inflater.inflate(R.layout.econfragment, container, false); 
    } 

    public void onResume() { 
     super.onResume(); 
     questionContainer = (TableLayout) getActivity().findViewById(R.id.questionContainer); 

     LayoutInflater inflater = (LayoutInflater) getActivity(). 
     getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     //these lines are my first attempt to try and get the questions to repopulate after returning 
     //from pressing back - as of yet, they don't repopulate the screen: 
     //View econFragment = inflater.inflate(R.layout.econfragment, null); 
     //container.addView(econFragment); 

     int leftMargin=5; 
     int topMargin=5; 
     int rightMargin=5; 
     int bottomMargin=5; 
     while (pos < 10) { 
     View question = inflater.inflate(R.layout.question, null); 
     question.setId(pos); 
     pos++; 
     TableRow tr = (TableRow) question; 
     TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
       TableLayout.LayoutParams.MATCH_PARENT, 
       TableLayout.LayoutParams.WRAP_CONTENT); 
     trParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); 
     tr.setLayoutParams(trParams); 
     questionContainer.addView(tr); 
     } 
     Log.d("Econ", "onResume"); 
    } 

    public void onAttach(Activity activity) { 
     super.onAttach(activity); 
     Log.d("Econ", "onAttach"); 
    } 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Log.d("Econ", "onCreate"); 

    } 

    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     Log.d("Econ", "onActivityCreated"); 
    } 

    public void onStart() { 
     super.onStart(); 
     Log.d("Econ", "OnStart"); 
    } 

    public void onPause() { 
     super.onPause();  
     Log.d("Econ", "onpause"); 
    } 

    public void onStop() { 
     super.onStop(); 
     Log.d("Econ", "onstop"); 
    } 

    public void onDestroyView() { 
     super.onDestroyView(); 
     Log.d("Econ", "ondestroyview"); 
    } 

    public void onDestroy() { 
     super.onDestroy(); 
     Log.d("Econ", "ondestroy"); 

    } 

    public void onDetach() { 
     super.onDetach(); 
     Log.d("Econ", "ondetach"); 
    } 
} 

答えて

0

質問私は私のアプリの他の分野に取り組んだとしてちょっとのBackburnerに入れてしまいました。ソリューションは単純なものであることが分かりました。コードに記載されているpos変数は静的なので、whileループは0から10までリクルートできませんでした。ここに答えがあります:Even though onCreateView runs again, View does not properly reassemble after BACK press?

1

各アクティビティは、のonCreateからonDestroyに自身の寿命サイクルを有します。ここに絵を見て、非常に詳細な記事を取る:Activities Lifecycle

あなたの活動がサイクルものの行くと、ユーザがか戻るボタン PowerButton を押したときに自動的に死にます。電源を入れ直すと、アクティビティが始まります(onCreate)。

あなたは保存して負荷機能を実装し、に状態を保存する必要がありますがonResumeコールバックコールバックおよび負荷状態をonPaused。再起動の間、あなたの活動の状態が失われるのを防ぎます。

+0

ありがとうございました、私は明日の朝にもう少し深く提供したリンクを読んでいただきます。あなたが見ることができるように、私は各メソッドのログエントリを持っている、ので、私はすでに、私の状態onPauseで少しを保存しようとし始めていたので、私は、私はonPause後に私のものを失っていたことを見ることができましたが、私は理由として混乱しています私が戻ったときにUIが構築されているので、UIを単に再作成するのではなく、返されたときに再実行します。 私は方法などputInt、putString、周りよりになりますが、私は私がこれらのタイプの方法を介してUIを保存する方法を把握することは、ストレッチのビットになると思います。 – Davek804

+0

記事を実行した後、私は吸収しなければならない、私はここで問題を知っていると思う。フラグメントでは、onCreateViewはonCreateの後で実行されます(私の主なアクティビティはこのメソッドから構築されます)。だから私はレイアウトに要素を追加することはできません(これはonCreateViewで膨らんでいます)。何か案は? – Davek804