0

ScanLocateアクティビティからアクティビティのアレイリストを取得しようとしていますUpdateLocation

method を使用して、 ArrayList を設定するstartActivityForResultメソッドを呼び出しています。次に、 ArrayList をクラスに送信したいと考えています。scanwifiListUpdate Location

私は電話startActivityForResultすることから始めUpdate Locationます:

private void getScan(){
    //Create an intent to start ScanLocate
    final Intent i = new Intent(this, ScanLocate.class);
    //Start scanLocate with request code
    startActivityForResult(i, REQUEST_READINGS);
}

次に、メソッドScanLocateを作成しましたsendData(注: チェックにより、その時点で ArrayList データが損なわれていないことが確認されます)。

private void sendData(){
    //create a new intent as container for the result
    final Intent readings = new Intent(this, UpdateLocation.class);

    //check that data is in wifiList
    for(String s:wifiList){
        Log.v(TAG,"List Items: " + s);
    }

    //create bundle for string array
    Bundle b = new Bundle();
    b.putStringArrayList(key, wifiList);

    //add readings to send to updateLoc
    readings.putExtras(b);

    //set code to indicate success and attach Intent
    setResult(RESULT_OK, readings);

    //call finish to return
    finish();
}

最後の部分UpdateLocationonActivityResult:

    @Override
        public void onActivityResult(int requestCode, int resultCode, Intent readings){
    super.onActivityResult(requestCode, resultCode, readings);

    //check if request code matches the one set above
    if(requestCode == REQUEST_READINGS){

        //check if sendData() in ScanLocate was successful
        if(resultCode == RESULT_OK){
            //get the readings from the Intent
            Log.v(TAG, "HERE");
            result = getIntent().getExtras().getStringArrayList(ScanLocate.key);
            Log.v(TAG, "HERE2");

            for(String s : result) {
                Log.v(TAG, "Location 5: " + s);
            }
        }else{
            //ScanLocate was unsuccessful
        }
    }
}

最初"Here"は表示されますが、次の行に落ちgetStringArrayList()、null ポインター例外がスローされます。

ドキュメントとここの以前の質問に目を通しましたが、何が問題なのかわかりません。

アドバイスをいただければ幸いです。

以前の質問:

startactivityforResult が機能しない

ArrayList を StartActivityForResult アクティビティに渡す方法

4

1 に答える 1