我想知道如何完成检查 Activity 是否是有 Intent 启动的。
我尝试过的:
我尝试检查对象是否为空,但由于我的设置,我无法检查。我也尝试过使用代码执行,但也失败了。
我的代码:
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("Title", one);
intent.putExtra("Description", two);
/////////////////////////
Intent intent = getIntent();
String title = intent.getStringExtra("Title");
String description = intent.getStringExtra("Description");
非常感谢!
最佳答案
所有 Activity 都以 Intent 开始,
但是我们可以检查Intent是否在bundle中有详细信息? 就像你的情况一样 -
Intent intent = getIntent();
if( intent!= null && intent.getExtras() != null
&& !intent.getExtras().getString("Title").equals("")
&& !intent.getExtras().getString("Description").equals("") ) {
// Activity started with sending title & description
}
else {
// Activity started without sending title & description
}
关于java - 检查用户是否来自 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50223513/