2012-02-24 7 views
0

インテントを介してデータを1つのアクティビティから別のアクティビティに渡している間に値がNULLになりました。インテントから別のアクティビティにデータを渡している間にヌル値を取得する

1Activityから渡す:

     int s = position;  
      String str=adapter.getId(position); 
       int Type=DeviceType; 
       Bundle bunch=new Bundle(); 
       bunch.putString("id", str); 
       bunch.putInt("DeviceType",Type); 
       bunch.putInt("position", s); 
       Intent It=new Intent(); 
       It.setClass(PYSActivity.this,GridImages.class); 
       It.putExtras(bunch); 
       startActivity(It); 

を2活動でここにRetriveing:

   super.onCreate(savedInstanceState); 
    setContentView(R.layout.main1); 

       Bundle b = this.getIntent().getExtras(); 
       AppID=b.getString("id"); 
       DeviceType=b.getInt("DeviceType"); 
       Position=b.getInt("position"); 

       list=(GridView)findViewById(R.id.list); 
    adapter1=new LazyAdapter1(this,mStrings,like,Rate,Id,img); 
    list.setAdapter(adapter1); 

答えて

1

このような何か:

活動1:

int myInt = 5; 
    String myString = "hi"; 

    ... 
    Intent Intent = new Intent(...); 
    intent.putExtra("string_key", myString); 
    intent.putExtra("int_key", myInt); 
    startActivity(intent); 

活動2:

int getInt; 
    String getString; 
    ... 

    Bundle extras = getIntent().getExtras(); 

    // Read the extras data if it's available. 
    if (extras != null) 
    { 
     getInt = extras.getInt("int_key"); 
     getString = extras.getString("string_key"); 
    } 
0

なぜあなただ​​けの意図を使用してバンドルを作成しています。

  it.putExtra("id", str); 
      it.putExtra("DeviceType",Type); 
      it.putExtra("position", s); 
+0

その後、私が使用している –

+0

を取得中に、int型のID = getIntentを()。 getExtras()。getInt( "id"); null値を取得していますが、 –

+0

あなたの検索方法はOKです。うまくいくはずです。 – Altaf

関連する問題