1. 程式人生 > >Activity頁面跳轉資料傳遞 Bundle

Activity頁面跳轉資料傳遞 Bundle

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String a="12";
        String b="22";
        String c="3";
        String d="4";
        String e="5";
        String f="6";
        Intent i=new Intent(MainActivity.this, OtherActivity.class);
        Bundle bundle=new Bundle();
        bundle.putCharSequence("a",a);
        bundle.putCharSequence("b",b);
        bundle.putCharSequence("c",c);
        bundle.putCharSequence("d",d);
        bundle.putCharSequence("e",e);
        bundle.putCharSequence("f",f);
        i.putExtras(bundle);
        startActivity(i);
    }
}

/*******************************************************************************************************************************************/

public class OtherActivity extends AppCompatActivity {

    private String TAG=OtherActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other_actvity);
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        String a = extras.getString("a");
        Log.e(TAG,a);
        String b = extras.getString("b");
        Log.e(TAG,b);
        String c = extras.getString("c");
        Log.e(TAG,c);
        String d = extras.getString("d");
        Log.e(TAG,d);
        String e = extras.getString("e");
        Log.e(TAG,e);
        String f = extras.getString("f");
        Log.e(TAG,f);

    }
}