My android learning experience 15 and android learning experience 15

Source: Internet
Author: User

My android learning experience 15 and android learning experience 15

Use Intent to redirect pages with returned results

Mainly used methods:

(1) Intent constructor: intent (current interface object, interface to jump to. class );

(2) onActivityResult (int requestCode, int resultCode, Intent data)

(3) startActivityForResult (Intent intent, int requestCode );

(4) setResult (int resultCode, Intent in); // write it on the page after the jump

(5) in. putExtra ("return", "returned turning result"); // used in conjunction with (4) to store the result key-value pairs

The Code is as follows: the first page

Package com. example. intentexample;

Import javax. security. auth. PrivateCredentialPermission;

Import android. support. v7.app. ActionBarActivity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. preference. PreferenceManager. OnActivityResultListener;
Import android. view. Menu;
Import android. view. MenuItem;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. TextView;

Public class MainActivity extends ActionBarActivity {

Private Button bt;
Private TextView TV;

Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Bt = (Button) findViewById (R. id. button1 );
TV = (TextView) findViewById (R. id. textView2 );
Bt. setOnClickListener (new OnClickListener (){

Public void onClick (View v ){
// TODO Auto-generated method stub
Intent intent = new Intent (MainActivity. this, factiworkflow. class );
StartActivityForResult (intent, 1 );
}
});
}
@ Override
Protected void onActivityResult (int arg0, int arg1, Intent arg2 ){
// TODO Auto-generated method stub
Super. onActivityResult (arg0, arg1, arg2 );
If (arg0 = 1 & arg1 = 2 ){
TV. setText (arg2.getStringExtra ("return "));
}
}

}

 

Second Interface

Package com. example. intentexample;

Import javax. security. auth. PrivateCredentialPermission;

Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;

Public class facti1_extends Activity {
Private Button bt;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
SetContentView (R. layout. facti.pdf );
Bt = (Button) findViewById (R. id. button1 );
Bt. setOnClickListener (new OnClickListener (){

@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
Intent in = new Intent ();
In. putExtra ("back", "returned rotary results ");
SetResult (2, in );
Finish ();
}
});
}
}

 

Before page Jump

After page Jump:

The page returns the following results:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.