PowenKo, Android Tutorial,Bundle, change activity and pass data and return result.

January 12, 2012   ·   0 Comments

private final int SECONDARY_ACTIVITY_REQUEST_CODE=0;

  //create a new intent and specify that it's target is SecondaryActivity...
            Intent intent = new Intent(getApplicationContext(),newpage.class);
            //load the intent with a key "myKey" and assign it's value
            //to be whatever has been entered into the text field...
            intent.putExtra("title","xxx");
            //launch the secondary activity and send the intent along with it
            //note that a request code is passed in as well so that when the 
            //secondary activity returns control to this activity, 
            //we can identify the source of the request...
            startActivityForResult(intent, SECONDARY_ACTIVITY_REQUEST_CODE);



     @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
        String t1=extras.getString("returnKey"):

     }

newpage.class

     Intent intent=this.getIntent();
        Bundle bunde = intent.getExtras();
        String t_appslink_url=bunde.getString("title");

….. do something…..return…..to fish page..

 Intent intent = new Intent();
                //add "returnKey" as a key and assign it the value
                //in the textbox...
                intent.putExtra("returnKey","finish");
                //get ready to send the result back to the caller (MainActivity)
                //and put our intent into it (RESULT_OK will tell the caller that 
                //we have successfully accomplished our task..
                setResult(RESULT_OK,intent);
                //close this Activity...
                finish();

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon