-1

I would like to Start a new activity from my custom dialog, I have a simple Button and I want that when I press the button a new activity will start.

I try with Start:

Intent intent=new Intent(arg0.getContext(),IdResult.class);     
startActivityForResult(intent, 0);

but it doesn't work; how can I make this work?

kannappan
  • 2,250
  • 3
  • 25
  • 35
firco
  • 33
  • 1
  • 2
  • 5

3 Answers3

1

Use this

 public class CustomDialog extends Dialog implements OnClickListener {
      Button okButton, cancelButton;
      Activity mActivity;

      public CustomDialog(Activity activity) {      
        super(activity);
        mActivity = activity;
        setContentView(R.layout.custom_dialog);
        okButton = (Button) findViewById(R.id.button_ok);
        okButton.setOnClickListener(this);
        cancelButton = (Button) findViewById(R.id.button_cancel);
        cancelButton.setOnClickListener(this);
      }

      @Override
      public void onClick(View v) {       
        if (v == cancelButton)
            dismiss();
        else {
            Intent i = new Intent(mActivity, IdResult.class);
            mActivity.startActivity(i);
        }
      }
    }
Harinder
  • 11,776
  • 16
  • 70
  • 126
0

It seems that you start new activity from non-activity class. Just add intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

You can read more in reference page

Gregory Kalabin
  • 1,760
  • 1
  • 19
  • 45
0

just add the this code inside the custom dialog

Intent i = new Intent(MyActivity.this, ItemSelection.class);
mActivity.startActivity(i);
kannappan
  • 2,250
  • 3
  • 25
  • 35