Note that there are some explanatory texts on larger screens.

plurals
  1. POerror in DialogFragment show() method
    primarykey
    data
    text
    <p>I am getting <strong>java.lang.IllegalStateException: Activity has been destroyed.</strong> when i try to show a dialogfragment from an activity.</p> <p>I have seen many solutions in stackoverflow but those didnt solve my problem Error occurs in the following line</p> <blockquote> <p>dialogfragment.show(ft, "dialog");</p> </blockquote> <p>Code is given below.</p> <pre><code>class MyDialog extends DialogFragment { int mNum = 0; static MyDialog newInstance(){ return new MyDialog(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //dialog view Log.i("MyDialog", "onCreateview"); View v = inflater.inflate(R.layout.dialog, container, false); TextView v1 = (TextView) v.findViewById(R.id.text); v1.setText("dialog shown"); return v; } } public class DialogActivity extends FragmentActivity{ DialogFragment dialogfragment; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); } void show(){ FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment f = getSupportFragmentManager().findFragmentByTag("dialog"); if(f != null){ ft.remove(f); } dialogfragment = MyDialog.newInstance(); dialogfragment.setCancelable(false); dialogfragment.show(ft, "dialog"); dialogfragment.setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); } } </code></pre> <p>I am calling this method from an Activity class as</p> <pre><code>DialogActivity dl = new DialogActivity(); dl.show(); </code></pre> <p>Error log</p> <blockquote> <p>07-08 14:54:09.565: W/System.err(10390): java.lang.IllegalStateException: Activity has been destroyed 07-08 14:54:09.565: W/System.err(10390): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1314) 07-08 14:54:09.565: W/System.err(10390): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541) 07-08 14:54:09.565: W/System.err(10390): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525) 07-08 14:54:09.565: W/System.err(10390): at android.support.v4.app.DialogFragment.show(DialogFragment.java:138)</p> </blockquote> <p>I missed some part of code.now added it</p> <p>EDIT : </p> <blockquote> <p>Is there anyother way to call the show() method in DialogActivity from another Activity class??</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload