-1

I am new to android development,So I have created dynamic views using ViewPager and PagerAdapter. I am handling this logic in my ViewPagerHandler class. This starts in Activity A.

Now I want to add new views displayed in Activity A from a different Activity B. I need to access the PagerAdapter object to add views the to my arraylist and set that view as currentview.

I tried to pass ViewPagerHandler object to intent of Activity B, but failed with below stack trace.

 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.mak.test.weatherapp.ViewPagerHandler)
                                                                             at android.os.Parcel.writeSerializable(Parcel.java:1761)
                                                                             at android.os.Parcel.writeValue(Parcel.java:1709)
                                                                             at android.os.Parcel.writeArrayMapInternal(Parcel.java:777)
                                                                             at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)
                                                                             at android.os.Bundle.writeToParcel(Bundle.java:1181)
                                                                             at android.os.Parcel.writeBundle(Parcel.java:817)
                                                                             at android.content.Intent.writeToParcel(Intent.java:9480)
                                                                             at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4340)
                                                                             at android.app.Instrumentation.execStartActivity(Instrumentation.java:1610)
                                                                             at android.app.Activity.startActivityForResult(Activity.java:4472)
                                                                             at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
                                                                             at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
                                                                             at android.app.Activity.startActivityForResult(Activity.java:4430)
                                                                             at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
                                                                             at android.app.Activity.startActivity(Activity.java:4791)
                                                                             at android.app.Activity.startActivity(Activity.java:4759)
                                                                             at com.sjsu.cmpe277.weatherapp.MainActivity.onOptionsItemSelected(MainActivity.java:179)
                                                                             at android.app.Activity.onMenuItemSelected(Activity.java:3435)
                                                                             at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:368)
                                                                             at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
                                                                             at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
                                                                             at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:674)
                                                                             at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
                                                                             at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
                                                                             at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
                                                                             at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
                                                                             at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
                                                                             at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
                                                                             at android.view.View.performClick(View.java:6256)
                                                                             at android.view.View$PerformClick.run(View.java:24697)
                                                                             at android.os.Handler.handleCallback(Handler.java:789)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                             at android.os.Looper.loop(Looper.java:164)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                          Caused by: java.io.NotSerializableException: com.mak.test.weatherapp.MainActivity
                                                                             at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1233)
                                                                             at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1597)
                                                                             at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1558)
                                                                             at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1481)
                                                                             at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1227)
                                                                             at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
                                                                             at android.os.Parcel.writeSerializable(Parcel.java:1756)

I have checked various post and which suggested to implement serializable in your class, I have implemented Serializable to all classes that I have used, but still getting this error.

Is there any way I can pass access that PagerAdapter Object from different activity and add my views to it.

1
  • 1
    "Is there any way I can pass access that PagerAdapter Object from different activity and add my views to it" -- no, sorry. Nov 5, 2017 at 23:41

1 Answer 1

0

Did you try to use Parceler?

That's an amazing library for using Parcels for send customs objects thru activities and fragments

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.