【发布时间】:2017-01-20 09:55:39
【问题描述】:
我有代码可以将用户从底部栏引导到个人资料页面。
private void startNewIntent(Class className, String uid){
Intent intent = new Intent(act, className);
intent.putExtra("uid", uid);
act.startActivity(intent);
act.finish();
}
className = DisplayProfile.class;
if(FirebaseAuth.getInstance().getCurrentUser() != null){
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
startNewIntent(DisplayProfile.class, uid);
} else {
startNewIntent(EmailPasswordActivity.class);
}
在 ProfileActivity.java 中
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
我也尝试使用Bundle = getIntent().getExtra() 获得相同的结果。我见过类似的问题。好像是这样:getIntent() Extras always NULL
我试过了
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
但getIntent().getExtra != null 仍然是假的。
感谢您的帮助和建议。
编辑:为 startNewIntent() 添加上下文
【问题讨论】:
-
可能没关系,但
act是什么? -
活动行为我猜?
-
getIntent() 是 null 还是只是 getExtra() ??
-
act 是将启动 ProfileActivity 的当前活动。我检查了 getIntent() 不为空,它似乎是正确的 Intent。
-
显示你如何调用
startNewIntent方法
标签: android android-intent android-activity