How can I open another activity that is not the main activity?

0

I want to open from a notification the acitivity main and another depending on a parameter but I can only open the main one and when receiving notifications with the open app this closes the code is as follows.

private void enviarNotificacion(RemoteMessage.Notification messageBody) {                                                           
    Intent intent;                                                                                                                  
    Notification notificacion;                                                                                                      

    if(messageBody.getClickAction().compareTo(null)==0){                                                                            
        intent = new Intent(getApplicationContext(),MainActivity.class);                                                            
    }else{                                                                                                                          
        intent = new Intent(getApplicationContext(),MostrarWeb.class);                                                               
    }                                                                                                                               


    PendingIntent pendingIntent = 
    PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);                                 

    Uri defaultSoundUri= 
    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);                                          
    notificacion = new NotificationCompat.Builder(this)                                                                             
        .setSmallIcon(getResources().getIdentifier(messageBody.getIcon(), 
        "drawable", getApplicationContext().getPackageName()))
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), 
         R.drawable.ic_noti))                                         
        .setContentTitle(messageBody.getTitle())                                                                                
        .setContentText(messageBody.getBody())                                                                                  
        .setAutoCancel(true)                                                                                                    
        .setContentIntent(pendingIntent)                                                                                        
        .setSound(defaultSoundUri)                                                                                              
        .setContentIntent(pendingIntent)                                                                                        
        .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})                                                                   
        .build();                                                                                                               


    NotificationManager notificationManager =                                                                                       
        (NotificationManager) 
    getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);                           

    notificationManager.notify(0,notificacion);}
    
asked by aitorlv 17.04.2018 в 22:34
source

2 answers

1

You should create a Intent such that:

Intent nombreIntent = new Intent(CurrentActivity.this, MostrarWeb.class);
CurrentActivity.this.startActivity(nombreIntent);

And in the manifest xml (app > manifests > AndroidManifest.xml):

<activity android:label="@string/app_name" android:name="MostrarWeb"/>
    
answered by 18.04.2018 в 08:35
1

Using messageBody.getClickAction() in onMessageReceived() will always return a null value, get information in this way by specifying the name of the key:

messageBody.getData().get(<nombre de key>) 

but for this you must make sure that the payload actually has this key and its value:

 'click_action' => 'provengo de la activity ...'
    
answered by 18.04.2018 в 19:52