Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 按下主页按钮后,DialogFragment不会继续_Android_Android Fragments_Android Dialogfragment - Fatal编程技术网

Android 按下主页按钮后,DialogFragment不会继续

Android 按下主页按钮后,DialogFragment不会继续,android,android-fragments,android-dialogfragment,Android,Android Fragments,Android Dialogfragment,我有一段代码,其中在主活动顶部打开一个片段对话框。当我按下home按钮,然后再次打开片段时,不会调用onActivityCreated。为什么呢 多谢各位 public class ProgressDialog extends DialogFragment { private ProgressBar progress; private TextView percentText; private TextView descriptionText; @Override public Dialog

我有一段代码,其中在主活动顶部打开一个片段对话框。当我按下home按钮,然后再次打开片段时,不会调用onActivityCreated。为什么呢

多谢各位

public class ProgressDialog extends DialogFragment {

private ProgressBar progress;
private TextView percentText;
private TextView descriptionText;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {


    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.download_screen,null);

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Please Wait....");
    builder.setView(v);
    builder.setNegativeButton("CANCEL",null);

    progress = v.findViewById(R.id.progressBar);
    percentText = (TextView) v.findViewById(R.id.percent);
    descriptionText = (TextView) v.findViewById(R.id.description);

    this.setCancelable(false);
    final AlertDialog dialog = builder.create();

    return dialog;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if(savedInstanceState==null) {
        percentText.setText("Total Requests: 0");
        progress.setIndeterminate(true);
        descriptionText.setText("Analyzing Data....");
    }else{
        progress.setIndeterminate((boolean)savedInstanceState.get("indeterminate"));
        descriptionText.setText((String)savedInstanceState.get("description"));
        percentText.setText((String)savedInstanceState.get("percent"));
        progress.setMax((int)savedInstanceState.get("max"));
    }

}
}

请参见下面链接中的片段生命周期

在这里,您可以看到在片段的
onCreateView()
之后和
onResume()
之前调用了
onActivityCreated()

因此,当您通过按home按钮最小化片段时,它将调用
onPause()
方法


当你导航回你的片段时,它会调用onResume()

当我导航回片段时,它不会调用onActivityCreated。这就是我要说的,它不会调用onActivityCreated(),因为它会调用onResume()。您可以将捆绑包从onActivityCreated复制到另一个变量,并在onResume()中检查该变量,以及通常在何时调用onActivityCreated?在活动的onCreate()方法返回时调用。