android - 活动可见时立即显示 toast
问题描述
每当用户可以看到活动但消息根本不显示时,我都会尝试显示敬酒。
我有活动 X 在某些时候调用:
Intent t = new Intent(this, MainActivity.class);
t.putExtra( "toast", getString(R.string.subscribingInBackground));
t.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(t);
finish();
在 MainActivity 除了我还有很多其他的东西:
@Override
public void onResume() {
super.onResume();
if (this.adView != null) {
this.adView.resume();
}
String toast = getIntent().getStringExtra("toast");
if (toast != null)
Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
}
但toast
始终为空
我究竟做错了什么?
解决方案
您FLAG_REORDER_TO_FRONT
建议您相信该活动已经存在。如果是这样,该活动将被调用onNewIntent()
,并且Intent
交付给onNewIntent()
将有你的额外。getIntent()
返回Intent
最初用于创建活动的 。
推荐阅读
- ios - 我怎样才能有两个不同的表格视图单元格,总是成对的,显示在同一个表格视图中?
- python - 如何使用多个四方查询进行循环并将每个新查询添加到数据框
- android - 模拟器无法在 MacO 上运行。模拟器声称操作系统已过时
- javascript - 如何在其他子菜单关闭时一次打开 1 个子菜单
- javascript - 如何在Javascript中分配具有相同属性的多个对象
- bash - `exec <&-` 有什么作用?
- d3.js - 为什么 phantomjs page.render 不捕获我的 D3 svg?
- r - 如何通过列表中的数据框名称联合大量数据框
- python - BeautifulSoup - 在这个 HTML 中查找链接
- java - 在移动到另一个片段并返回到它的同时保存片段内的 textView 值的正确方法是什么?