2

HI

I have a MainActivity Class which extends DashboardActivity Class. In Main activity class there are top action bar which when click will go to AddReminderActivity class. The action of the top action bar is defined in Dashboard Activity Class as

private void createReminder() {
    // TODO: fill in implementation
    Intent intent = new Intent(DashboardActivity.this,AddReminderActivity.class);
    Log.i("in OnActivityResult", "create reminder called");       
    startActivityForResult(intent, ACTIVITY_CREATE);
    Log.i("in OnActivityResult", "Start Activity called Result");       
}

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        Log.i("in OnActivityResult", "Activity Result" + resultCode);       
        super.onActivityResult(requestCode, resultCode, intent);
        Log.i("in OnActivityResult", "Activity Result" + resultCode);    
        Log.i("in OnActivityResult", "intent Result" + intent.getExtras());    
        Bundle extras = intent.getExtras();
        Toast.makeText(getApplicationContext(),resultCode, Toast.LENGTH_SHORT).show();
        switch(requestCode){
        case ACTIVITY_CREATE:
              if (resultCode == Activity.RESULT_OK) {
                String title = extras.getString(ReminderDBAdapter.KEY_REMINDER_TITLE);
                String content = extras.getString(ReminderDBAdapter.KEY_REMINDER_CONTENT);
                mDbHelper.createReminder(title, content);
                mDbHelper.close();
              }
        startActivity(new Intent(this,ListReminder.class));
            break;

        }
        // TODO: fill in rest of method

    }

On the AddReminderActivityClass I have called

btnSubmitReminder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Bundle bundle = new Bundle();

            bundle.putString(ReminderDBAdapter.KEY_REMINDER_TITLE, mReminderTitle.getText().toString());
            bundle.putString(ReminderDBAdapter.KEY_REMINDER_CONTENT, mReminderContent.getText().toString());
            if(mRowId != null){
                bundle.putLong(ReminderDBAdapter.KEY_ROWID, mRowId);
            }
            System.out.println(mReminderTitle.getText().toString());
            Toast.makeText(getApplicationContext(), mReminderTitle.getText().toString(), Toast.LENGTH_SHORT).show();
            Intent mIntent = new Intent();
            mIntent.putExtras(bundle);
            //setResult(RESULT_OK, mIntent);
            if (getParent() == null) {
                  setResult(DashboardActivity.RESULT_OK, mIntent);
            } else {
                getParent().setResult(DashboardActivity.RESULT_OK, mIntent);
            }

            Log.i("in OnActivityResult", "set result" +RESULT_OK);       
            finish();

        }
    });

But when returning back to OnActivityResult the intent returns null and following exception occurs. I cannot recognize what the problem is

05-16 17:25:09.686: ERROR/AndroidRuntime(441): FATAL

EXCEPTION: main 05-16 17:25:09.686: ERROR/AndroidRuntime(441): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.babz.android.businessReminder/com.babz.android.businessReminder.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0xffffffff 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread.access$2800(ActivityThread.java:125) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.os.Handler.dispatchMessage(Handler.java:99) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.os.Looper.loop(Looper.java:123) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at java.lang.reflect.Method.invoke(Method.java:521) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at dalvik.system.NativeStart.main(Native Method) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0xffffffff 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.content.res.Resources.getText(Resources.java:201) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.widget.Toast.makeText(Toast.java:258) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at com.babz.android.businessReminder.DashboardActivity.onActivityResult(DashboardActivity.java:68) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.Activity.dispatchActivityResult(Activity.java:3890) 05-16 17:25:09.686: ERROR/AndroidRuntime(441): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)

4 Answers 4

1

Uncomment the setResult method call.

Sign up to request clarification or add additional context in comments.

1 Comment

The setResult method has been called in the conditional statement.
1

as far as i can tell you get the exception when you try to get a value with a key that doesn't exist in the bundle, so in your case probably one of these:

String title = extras.getString(ReminderDBAdapter.KEY_REMINDER_TITLE);
String content = extras.getString(ReminderDBAdapter.KEY_REMINDER_CONTENT);

You can ask the bundle if the key exists by calling containsKey(String key) on the bundle, so i suggest you use that to find out if its the case or not.

1 Comment

Thanks. But i have debug and the value is coming in bundle.
1

As Guru said, you setResult() method is not being called. Thus the Intent is never being set.

I'm making a separate answer because there is a common problem that needs addressing: using the wrong setResult().

Make sure you use setResult(resultCode, intentData), NOT setResult(resultCode). I have to stress because many examples in many books use the latter, implying that the same intent that was sent into an Activity via startActivityForResult() will simply return that same Intent. ALL Intents MUST be added directly, or you'll get NULL for the Intent in onActivityResult() every time.

Comments

1

Actually, the problem is in this line:

Toast.makeText(getApplicationContext(),resultCode, Toast.LENGTH_SHORT).show();

This causes the exception because the parameter resultCode is an int and in this case the makeText() method assumes that the value is a resource ID (ie: R.string.something). In this case, however, the value is -1 and that generates this:

android.content.res.Resources$NotFoundException: String resource ID #0xffffffff

You were actually hoping to call the makeText() method that takes a String instead. Try this:

Toast.makeText(getApplicationContext(),"ResultCode: " + resultCode,
                  Toast.LENGTH_SHORT).show();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.