Android Pass Parameter to Activity

Passing parameter to Activity is fairly simple.

Code for the Activity which is calling


//from the calling activity
//use bundle to send the data
 Bundle b1 = new Bundle();
                b1.putString("url","http://www.androidlearner.com");
                intent = new Intent(activity, WebActivity.class);
                intent.putExtras(b1);




Code for the receiving activiy


//some default value
String url = "http://www.androidlearner.com";
//get the bundle
        Bundle b = getIntent().getExtras();
//check if null or not
        if(b!=null)
        {
//if not null get the value
            url=b.getString("url");
        }







Comments