Android開発ページのジャンプ、パラメーターを使用したジャンプ、フラグメントへのアクティビティ転送データ

1.ページジャンプ

2つのパラメーターが必要です。最初のLoginActivityは現在のクラスであり、もう1つのMainActivityはジャンプのターゲットクラスです。

 Intent intent = new Intent();
intent.setClass(LoginActivity.this,MainActivity.class);
startActivity(intent);

2.キャリングパラメータ

キーと値のペアを運ぶputExtraメソッドを使用します。これは以下のコードの2行目です。

Intent intent = new Intent();
intent.putExtra("userName", DataMap.get("name"));
intent.setClass(LoginActivity.this,MainActivity.class);
startActivity(intent);

3.アクティビティはデータをフラグメントに渡します

アクティビティ中(上記の1、2、データ進行関係を見てください)

        Intent intent=getIntent();
        String userName=intent.getStringExtra("userName");
        Bundle bundle = new Bundle();
        bundle.putString("userName",userName);
        userFragment.setArguments(bundle);//数据传递到fragment中

フラグメントで

        Bundle bundle =this.getArguments();//得到从Activity传来的数据
        String userName = null;
        if(bundle!=null){
            userName = bundle.getString("userName");
            System.out.println(userName);
        }

おすすめ

転載: blog.csdn.net/qq_41170600/article/details/108903783