-1

i want to send the OAScene scene object to next Activity class but i cant. it stops the aplication immediately..if i open other activity class without using the putExtra method it works ... but in my condition i need to send the object...

heres the code

public void setScene(OAScene scene) {
    final OAScene _scene = scene; 
    this.currentScene = scene;
    setColor(color_black);

    double dis; 
    dis = CalculationByDistance(latitudeOri, latitudeOri, scene.getLatitude(), scene.getLongitude());

    // Set the text fields of the notification bubble to match the data of
    // the selected scene.
    popup_name.setText("Name: " + scene.getName());
    popup_text.setText("Distance: " + dis + "m");

    more_info.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             OAScene scene=_scene; 
             Intent FacilityIntent;
             FacilityIntent = new Intent(getContext(), MapViewActivity.class);
             FacilityIntent.putExtra("scene", _scene);
             getContext().startActivity(FacilityIntent);
        }
     });
}

log..

01-20 15:50:31.196: E/AndroidRuntime(21403): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.hitlabnz.outdoorar.api.OAScene)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Parcel.writeSerializable(Parcel.java:1181)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Parcel.writeValue(Parcel.java:1135)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Parcel.writeMapInternal(Parcel.java:493)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Bundle.writeToParcel(Bundle.java:1612)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Parcel.writeBundle(Parcel.java:507)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.content.Intent.writeToParcel(Intent.java:6190)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1696)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.app.Activity.startActivityForResult(Activity.java:3190)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.app.Activity.startActivity(Activity.java:3297)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at com.hitlabnz.tutorialbasic.TutorialSceneNotificationBubble$2.onClick(TutorialSceneNotificationBubble.java:141)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.view.View.performClick(View.java:3620)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.view.View$PerformClick.run(View.java:14292)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Handler.handleCallback(Handler.java:605)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.os.Looper.loop(Looper.java:137)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at android.app.ActivityThread.main(ActivityThread.java:4512)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at java.lang.reflect.Method.invokeNative(Native Method)
01-20 15:50:31.196: E/AndroidRuntime(21403):    at java.lang.reflect.Method.invoke(Method.java:511)

code receive intent:

Intent i = getIntent();
        OAScene scene = (OAScene)i.getSerializableExtra("scene");
Alia Ramli Ramli
  • 405
  • 6
  • 18

2 Answers2

0

Try with this,

 facilityIntent= new Intent(YourCurrectActivity.this, MapViewActivity.class);
 facilityIntent.putExtra("scene", _scene);
 startActivity(facilityIntent);

in Second activity you can receive using

getIntent().getSerializableExtra("scene");
  • Try to follow for creating the object for predefined class. use facilityIntent instead of FacilityIntent
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
Aerrow
  • 12,086
  • 10
  • 56
  • 90
0

One option could be letting your custom class implement Serializable interface and then you can pass object instances in intent extra using putExtra(Serializable..) variant of the Intent#putExtra() method.

PSEUDO code:

//to pass :
   intent.putExtra("MyClass", obj);  

// to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");

For more explanation refer this.

Community
  • 1
  • 1
AndroidLearner
  • 4,500
  • 4
  • 31
  • 62