November 02, 2013

How to pass Boolean, Int, String, Integer ArrayList, String ArrayList, int list and String List with an intent.

           
                 In this blog I want to explain How to pass Boolean, Int, String, Integer ArrayList, String ArrayList, int list and String List with an intent.


Intent
                Intent is an object that is used to launch an activity or to return information  from an activity.  To start a new activity using startActivity(intent).  To get information from another activity we start activity using startActivityForResult(intent, requestCode).


               Here in  FromPage.java we are adding  Boolean, Int, String, Integer ArrayList, String ArrayList, int list and String List values to an intent. In ToPage.java We extract added values will retrieve from intent. 


FromPage.java

ArrayList<Integer>  IntArrayList = new  ArrayList<Integer>(Arrays.asList(100,13,18,22,44,13));
ArrayList<String>  StringArrayList = new  ArrayList<String>(Arrays.asList("String1", "String2", "String3", "String4"));

        int[] intList = {4, 6, 3, 8, 2, 10};
        String[] StringList = {"String1", "String2", "String3", "String4"};

        Intent intent = new Intent(FrstPage.this, SecondPage.class);
        intent.putExtra("BoolValue", true);
        intent.putExtra("IntValue", 199);
        intent.putExtra("StringValue", "Test String");
        intent.putExtra("IntArrayList", IntArrayList);
        intent.putExtra("StringArrayList", StringArrayList);
        intent.putExtra("IntList", intList);
        intent.putExtra("StringList", StringList);
        startActivity(intent);



ToPage.java

            Intent intent = getIntent();
            boolean fullscreenAd =  intent.getBooleanExtra("BoolValue", false);
            int IntValue =  intent.getIntExtra("IntValue", 0);
            String StringValue =  intent.getStringExtra("StringValue");
            ArrayList<Integer> IntArrayList =  intent.getIntegerArrayListExtra("IntArrayList");
            ArrayList<String> StringArrayList =  intent.getStringArrayListExtra("StringArrayList");
            int[] intList =  intent.getIntArrayExtra("IntList");
            String[] StringList =  intent.getStringArrayExtra("StringList");




2 comments:

  1. sir how can we pass the data from recyclerAdapter to another activity (for add to cart ) please help me sir...

    ReplyDelete