【发布时间】:2018-12-30 07:00:33
【问题描述】:
每当活动对用户可见但消息根本不显示时,我都会尝试显示敬酒。
我有活动 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 始终为空
我做错了什么?
【问题讨论】:
-
我已经通过调试检查了 toast 是否为空
-
您没有调用
show()函数 (Toast.makeText(...).show())。这不会使toast不为空,但仍然。 -
我注意到我在 makeText 之后忘记了
.show(),但由于toast始终为空,所以还没有工作 -
请尝试使用get string from xml as
getResources().getString(R.string.subscribingInBackground);
标签: android android-intent activity-lifecycle android-toast