How do I get extra data from intent on Android?

后端 未结 16 2264
清歌不尽
清歌不尽 2020-11-21 11:01

How can I send data from one activity (intent) to another?

I use this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra(\         


        
16条回答
  •  隐瞒了意图╮
    2020-11-21 11:49

    You can get any type of extra data from intent, no matter if it's an object or string or any type of data.

    Bundle extra = getIntent().getExtras();
    
    if (extra != null){
        String str1 = (String) extra.get("obj"); // get a object
    
        String str2 =  extra.getString("string"); //get a string
    }
    

    and the Shortest solution is:

    Boolean isGranted = getIntent().getBooleanExtra("tag", false);
    

提交回复
热议问题