ScanLocate
アクティビティからアクティビティのアレイリストを取得しようとしていますUpdateLocation
。
method を使用して、 ArrayList を設定するstartActivityForResult
メソッドを呼び出しています。次に、 ArrayList をクラスに送信したいと考えています。scan
wifiList
Update 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();
}
最後の部分UpdateLocation
はonActivityResult
:
@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 ポインター例外がスローされます。
ドキュメントとここの以前の質問に目を通しましたが、何が問題なのかわかりません。
アドバイスをいただければ幸いです。
以前の質問: