Karthi
Karthi

Reputation: 125

Dialog not displaying from fragmentActivity in android

I want to display a dialog inside the class that extends FragmentActivity.I have tried in many ways.Atlast I tried this link. I have tried the samething but iam getting the following error message.

  05-14 10:15:28.821: E/AndroidRuntime(2927): java.lang.IllegalStateException: Activity has been destroyed
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at   android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1342)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.DialogFragment.show(DialogFragment.java:127)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.sriseshaa.ecgviewer.FragmentTabActivity$1$1.run(FragmentTabActivity.java:70)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Handler.handleCallback(Handler.java:725)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Handler.dispatchMessage(Handler.java:92)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Looper.loop(Looper.java:137)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.app.ActivityThread.main(ActivityThread.java:5039)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at java.lang.reflect.Method.invokeNative(Native Method)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at java.lang.reflect.Method.invoke(Method.java:511)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at dalvik.system.NativeStart.main(Native Method)

FragmentTabActivity.java:70 is

   adFragment.show(getSupportFragmentManager(), "dialog");

I have called the dialog by the following code snippet

          Bundle bundle = new Bundle();  
          bundle.putString("title", "Message");  
          bundle.putString("message", StaticHelper.l);  
          bundle.putString("positive", "Ok");  
          bundle.putString("negative", "Cancel");  
          // bundle.putInt("id", mIndex++);  
          AlertDialogFragment adFragment = new AlertDialogFragment();  
          adFragment.setArguments(bundle);  
          adFragment.show(getSupportFragmentManager(), "dialog");  

What I have missed? and what is the problem in this? please help me.Thank u!!

Upvotes: 0

Views: 1339

Answers (1)

Anu
Anu

Reputation: 7177

If you really want to display an alertdialog what is your problem of using AlertDialog.Builder as following.

    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setIcon(R.drawable.ic_launcher);
    dialog.setTitle("Title");
    dialog.setMessage("Message");
    dialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

        }
       });
       dialog.setNegativeButton("no", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
      });
      dialog.show();

Upvotes: 1

Related Questions