CODE
this.getApplicationContext().getContentResolver().registerContentObserver(
android.provider.Settings.System.CONTENT_URI,
true, new ContentObserver(new Handler()) {
public void onChange(boolean selfChange) {
Toast.makeText(audioServices.this, "Working..", Toast.LENGTH_SHORT).show();
//dispVC();
dialog = new Dialog(audioServices.this);
dialog.setContentView(R.layout.vc);
// set the custom dialog components - text, image and button
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
//System.out.println("Works!");
}
});
This is the logcat.
Note – 01-09 17:54:43.137: E/AndroidRuntime(7210): at com.torcellite.popupvc.audioServices$1.onChange(audioServices.java:59)
Line 59 is dialog.show();
—EDIT—
So, I changed the code to this.
Intent dialogIntent = new Intent(audioServices.this, vcDialog.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
audioServices.this.startActivity(dialogIntent);
My app still crashes. This is the logcat.
A service doesn’t have any UI elements, so can’t show a dialog box. A dialog can only be added from an Activity context. You can either call an activity that does have a UI, with a dialog theme if you’d like or it might be better to create a notification which is the preferred option for Android alerts.
EDIT
Based on your new code, your intent is fine. Instead add the following to your manifest in the application tag: