I have an Activity A in TabHost, A startActivityForResult(B) then B startActivityForResult(C).
The problem I meet is that:
In C when I setResult(RESULT_OK, intent), occur
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.hackingtrace.vancexu/com.hackingtrace.vancexu.task.B}: java.lang.NullPointerException
In B, I start C by
setTimeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(view.getContext(), TaskTimeSet.class);
i.putExtra(TasksDbAdapter.KEY_ROWID, mRowId);
Calendar c = Calendar.getInstance();
Date d = c.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String now = sdf.format(d);
i.putExtra("date", now);
startActivityForResult(i, ACTIVITY_EDIT_TIME);
}
and in C, I setResult by
confirmBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.putExtra("date", resultDate);
int h = timePicker.getCurrentHour();
int m = timePicker.getCurrentMinute();
String time = "" +h+":"+m;
Log.d(TAG, time);
intent.putExtra("time", time);
setResult(RESULT_OK, intent);
finish();
}
});
then in B I receive the result by
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
Log.d(TAG, "I am in " + requestCode + resultCode);
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == ACTIVITY_EDIT_TIME) {
if (resultCode == RESULT_OK) {
Log.d(TAG, "OK time set");
String[] dateArr = intent.getStringExtra("date").split("-");
String[] timeArr = intent.getStringExtra("time").split(":");
int year = Integer.parseInt(dateArr[0]);
int month = Integer.parseInt(dateArr[1]);
int day = Integer.parseInt(dateArr[2]);
int hour = Integer.parseInt(timeArr[0]);
int minute = Integer.parseInt(timeArr[1]);
Log.d(TAG, ""+year+month+day+hour+minute);
}
}
}
But I never get the “Log.d(TAG, “”+year+month+day+hour+minute);” run normally.
I have tried:
1:
if (getParent() == null) {
setResult(Activity.RESULT_OK, intent);
}
else {
getParent().setResult(Activity.RESULT_OK, intent);
}
not work 🙁
2:
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
the error “java.lang.RuntimeException” not occur, but the requestCode and resultCode is 0 always.
In C I putExtra 2 string (resultDate and time), but I miss the point that resultDate may not be initialized when it is be put into intent. So I got the Error:
java.lang.NullPointerException.