【发布时间】:2014-09-22 15:28:05
【问题描述】:
我在 AlarmManager 中显示 AlertDialog。 DialogNotification(警报对话框) - 清单中的活动:
<activity
android:name=".notification.DialogNotification"
android:label="@string/title_activity_dialog_notification"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
我希望即使程序没有运行也能显示对话,但是当我进入应用程序时,对话框会在启动画面中显示,但我没有给他打电话。我该如何解决?
public class DialogNotification extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("Log", "onCreate DialogNotification");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.app_icon)
.setTitle(R.string.time_to_call_your_clients)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent notificationIntent = new Intent(DialogNotification.this, SplashActivity.class);
startActivity(notificationIntent);
dialog.cancel();
DialogNotification.this.finish();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
DialogNotification.this.finish();
}
}).show();
}
}
【问题讨论】:
-
那是因为您正在调用 onCreate 上的对话框。每次打开应用都会显示
-
在 .show() 调用上放一个断点......当你看到堆栈和你所在的函数时应该很明显......
标签: android android-activity dialog