民间,
我创建了一个对话框片段,它将显示带铃声的Dialog。但是,铃声正在播放,白色空白页面即将到来。
请指导我哪里出错了。
AlarmDialog.java
public class AlarmDialogPopUp extends Activity {
Ringtone ringtone;
Long rowId;Constants.TableTypes fragType;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = this;
Intent intent = getIntent();
rowId = intent.getExtras().getLong(DatabaseHandler1.KEY_ID);
fragType = (Constants.TableTypes) intent.getExtras().get(DatabaseHandler1.fragmentidenifier);
// Get the alarm ID from the intent extra data
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(AlarmDialogPopUp.this, uri);
ringtone.play();
}
@Override
protected Dialog onCreateDialog ( int id)
{
super.onCreateDialog(id);
// Build the dialog
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("ALARM REMINDER");
alert.setMessage("Check Your Reminder");
alert.setCancelable(false);
alert.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ringtone.stop();
// Constants.TableTypes fragType = (Constants.TableTypes) intent.getExtras().get(DatabaseHandler1.fragmentidenifier)
Intent intent = new Intent(AlarmDialogPopUp.this, PostClickNotificationActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
//getApplicationContext().startActivity(notificationIntent);
intent.putExtra(DatabaseHandler1.KEY_ID, rowId);
intent.putExtra(DatabaseHandler1.fragmentidenifier, fragType);
startActivity(intent);
AlarmDialogPopUp.this.finish();
}
});
// Create and return the dialog
AlertDialog dlg = alert.create();
//dlg.show();
dlg.show();
return dlg;
}
}
我已尝试过create method,show()其他帖子中提到的所有内容。但是,它不起作用。它响了,一页空白。
答案 0 :(得分:1)
在onCreate方法中显示您的对话框,如下所示
public class AlarmDialogPopUp extends Activity {
Ringtone ringtone;
Long rowId;Constants.TableTypes fragType;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = this;
Intent intent = getIntent();
rowId = intent.getExtras().getLong(DatabaseHandler1.KEY_ID);
fragType = (Constants.TableTypes) intent.getExtras().get(DatabaseHandler1.fragmentidenifier);
// Get the alarm ID from the intent extra data
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(AlarmDialogPopUp.this, uri);
ringtone.play();
displayDialog();
}
public void displayDialog()
{
// Build the dialog
final AlertDialog.Builder alert = new AlertDialog.Builder(AlarmDialogPopUp.this);
alert.setTitle("ALARM REMINDER");
alert.setMessage("Check Your Reminder");
alert.setCancelable(false);
alert.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ringtone.stop();
// Constants.TableTypes fragType = (Constants.TableTypes) intent.getExtras().get(DatabaseHandler1.fragmentidenifier)
Intent intent = new Intent(AlarmDialogPopUp.this, PostClickNotificationActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
//getApplicationContext().startActivity(notificationIntent);
intent.putExtra(DatabaseHandler1.KEY_ID, rowId);
intent.putExtra(DatabaseHandler1.fragmentidenifier, fragType);
startActivity(intent);
finish();
}
});
alert.show();
}
}
答案 1 :(得分:1)
class="form-control"
......这是错的。通常,您正在调用活动的dlg.show();
方法。但是这已被弃用,您应该创建自己的对话框,或使用showDialog(int)
删除DialogFragment
内的dlg.show()
,并在onCreateDialog()
中调用showDialog(0)
。