0

I have a set of activities in an application, where most of the activities has a common image. I want that after clicking on the image a dialog box will open and do some task as switching to another activity. This will be same for all the activities. But it is showing some error. Please help me resolve this

Here is the activity's onclick event

ImageView imgMenu = (ImageView) findViewById(R.id.imgMenu);
    imgMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
         Intent intent = FeatureMenu.ShowMenu(getApplicationContext());
            if (intent != null) {
                startActivity(intent);
            }
        }
    });

And this is a static class to handle the common functions:

public class FeatureMenu {
public static Intent intent;
public static Intent ShowMenu(final Context mcontext) {

    Dialog d = new Dialog(mcontext);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.menu_layout);
    ImageView abc = (ImageView) d
            .findViewById(R.id.abc);
    abc.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             intent=new Intent(mcontext,
                    xyz.class);

        }
    });
    d.show();
    return intent;

}
}
Sanghita
  • 1,307
  • 3
  • 16
  • 28

2 Answers2

0

Your dialog connected to a specific context(activity) when you are living this context your dialog cannot be active anymore. Try to dismiss the dialog before you living the activity.

Evgeni Roitburg
  • 1,958
  • 21
  • 33
0

Try using AsyncTask and in the onpreexecute() method, you can start the dialog box and pass the context and in the doinbackgroung() method you can run your own code and then in the onpostexecute() method, you can dismiss the dialog box.

Try this post: progressDialog in AsyncTask

Community
  • 1
  • 1
mike20132013
  • 5,357
  • 3
  • 31
  • 41