0

I am new in android. I want to send an object(object of p class) to first activity via onActivityForResult(). I write this code but when i use putSerializable(), first activity not run and i remain in MainActivity class. Why? How can i solve this problem?

MainActivity:

class MainActivity implements Serializable{
PClass p;
...
Intent intent=new Intent();
if(resultCode){         
    if(json!=null){


        Bundle b=new Bundle();
        b.putSerializable("p", p);
        b.putString("result", json);
        intent.putExtras(b);

        }
                    setResult(RESULT_OK, intent);
                }
                else
                    setResult(RESULT_CANCELED, intent);
                MainActivity.this.finish();    
  }

FristClass:

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 1) {
   if (resultCode == RESULT_OK) {
Bundle b=data.getExtras();
    if(b!=null)
        p=(P)b.getSerializable("p");

        String result=b.getString("result");
     }
}

when i comment this line (b.putSerializable("p", p);) my FirstActivity run but if this line not comment, first activity not run and reamin on mainActivity class :(

user3209380
  • 169
  • 1
  • 2
  • 14
  • your PClass class must implement parcelable. Also MainActivity does not extend Activity. http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents – Raghunandan Jan 18 '14 at 08:37
  • MainActivity extends Activity and why i impelement Parcelable in PClass? – user3209380 Jan 18 '14 at 09:52
  • and PClass implements Serializable. – user3209380 Jan 18 '14 at 09:54
  • bcoz you want to pass object of pclass form one activity to another that's why and that's how its done in andorid – Raghunandan Jan 18 '14 at 09:54
  • I am in MainActivity class and i want of this class send an PClass object to FirstClass. in MianActivity and PClass, i implement serializable but first activity not run. when i remove b.putSerializable(..) line of MainActivity class, FirstClass runs. WHy? what is problem of putSerializable(..)? – user3209380 Jan 18 '14 at 10:00
  • follow the link i posted and read the docs you will know why – Raghunandan Jan 18 '14 at 10:03

0 Answers0