8 notifications android dialog
我有通知显示.现在我希望这发生:
当我点击通知时,我想打开一个Dialog,我只打印一个字符串.
现在,当我创建通知时,我无法解决,在这里做什么:
...
Intent notificationIntent = new Intent(context, {how to open dialog});
...
Run Code Online (Sandbox Code Playgroud)
然后是1个按钮,例如"OK",它将关闭对话框.
请帮我.
谢谢.
我在我的一个应用中做到了这一点.在通知中,您需要执行以下操作:
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent("com.yourcompany.yourapp.MAINACTIVITY").putExtra("fromnotification", true);
Run Code Online (Sandbox Code Playgroud)
在您的主要活动中使用onResume()方法来检查这个额外的:
@Override
public void onResume()
{
super.onResume();
if (getActivity().getIntent().getBooleanExtra("fromnotification", false) == true)
{
getActivity().getIntent().removeExtra("fromnotification");
startActivityForResult(
new Intent("com.yourcompany.yourapp.DIALOGACTIVITY"), 123);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码显示具有对话框样式的活动,但没有理由说它无法在if语句中创建对话框.
| 归档时间: |
|
| 查看次数: |
5358 次 |
| 最近记录: |