Check if extras are set or not

前端 未结 5 1385
余生分开走
余生分开走 2020-12-13 01:28

Is there any way to check if an extra has been passed when starting an Activity?

I would like to do something like (on the onCreate() in the Activity):<

5条回答
  •  庸人自扰
    2020-12-13 02:14

    Well, I had similiar problem. in my case the null point exception was happen when I checked if my bundle.getString() was equall to null.

    here is how IN MY CASE I solved it:

    Intent intent = getIntent();        
        if(intent.hasExtra("nomeUsuario")){
            bd = getIntent().getExtras();
            if(!bd.getString("nomeUsuario").equals(null)){
                nomeUsuario = bd.getString("nomeUsuario");
            }
        }
    

提交回复
热议问题