我有代码,直接从底部栏用户到个人资料页。
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()添加了上下文
发布于 2016-09-13 17:41:32
不是签入onCreate(),而是签入onNewIntent():
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
@Override
protected void onNewIntent(Intent intent){
super.onNewIntent(intent);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
如果它出现在onNewIntent()中,这意味着您正在使用launchMode进行活动。这就是启动模式的行为。
发布于 2016-09-13 13:43:29
如果您的类名中已经存在".class"
,请避免使用它。
public void startNewIntent(Class className, String uid){
Intent intent = new Intent(act.this, className+".class");
intent.putExtra("uid", uid);
startActivity(intent);
}
下一阶段
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getExtras().getString("uid");
if(uid != null){
...
}
}
https://stackoverflow.com/questions/39459163
复制相似问题