【发布时间】:2017-12-06 15:13:41
【问题描述】:
如果我的意图为空,我想从意图发送数据,然后简单地打开我的主要活动。这是我的试用,但它不适合我。
从一个活动发送
intent = new Intent(this, MainActivity.class);
intent.putExtra("androidkey",body);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
接收时间
String uid;
Intent intent = getIntent();
uid = intent.getStringExtra("androidkey");
主Activity的oncreate方法
if (uid.equals("hello")){
startActivity(new Intent(MainActivity.this, About.class));
}else if (uid.equals("")||uid.equals(null)){
startActivity(new Intent(MainActivity.this, MainActivity.class));
}
请告诉我解决方法 因为它使我的应用程序崩溃。
实际上我想在我的代码中做的是
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data: " + remoteMessage.getData());
sendNotification(remoteMessage.getData().get("message"));
}
//Check if the message contains notification
if(remoteMessage.getNotification() != null) {
Log.d(TAG, "Mesage body:" + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
}
private void sendNotification(String body) {
if (body.equals("Image Upload Successfully")){
intent= new Intent(this, Image_Gallery.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Video Upload Successfully")){
intent = new Intent(this, Video_Gallary.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if (body.equals("Home Work Are Uploaded")){
intent = new Intent(this, HomeWork.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
当我的应用程序在前台并且通知到达它打开的完美页面但当应用程序不在前台时它打开 Mainactivity
所以请告诉我我该怎么做..?
【问题讨论】:
-
请发布 logcat 错误。它可以帮助每个人找到问题。
-
不要决定在 MainActivity 中加载哪个活动,当它已经启动时,但在创建意图之前。如果您有任何 android 密钥,请启动 About_School 活动,如果没有..启动 main。所以...决定在您创建 Intent 的地方加载哪个活动,而不是在结果活动中。
-
尝试在空对象引用上调用虚拟方法“java.lang.String android.content.Intent.getStringExtra(java.lang.String)”
标签: android firebase android-intent android-activity