P
P
penexe2016-01-12 08:54:19
Android
penexe, 2016-01-12 08:54:19

Do not save operations mode. App crashes?

Given:
MainActivity in it is a fragment with recyclerview, onClickListener is described in the adapter, opening a new NewsActivity.
When you press the back button from a new activity, a crash occurs.
I suspect that the context is incorrectly set at the start of the activity

pubViewHolder.getPublicationCard().setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent fullPublication = new Intent(v.getContext(), NewsActivity.class);
                    v.getContext().startActivity(fullPublication);
                }
            });

Help me to understand.
log:
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime: FATAL EXCEPTION: main
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime: Process: ru.cl.cl, PID: 29951
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.cl.cl/ru.cl.cl.MainActivity}: java.lang.RuntimeException: Parcel [email protected]: Unmarshalling unknown type code 3080309 at offset 788
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.access$900(ActivityThread.java:177)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:145)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5942)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:  Caused by: java.lang.RuntimeException: Parcel [email protected]: Unmarshalling unknown type code 3080309 at offset 788
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Parcel.readValue(Parcel.java:2222)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Parcel.readListInternal(Parcel.java:2520)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Parcel.readArrayList(Parcel.java:1836)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Parcel.readValue(Parcel.java:2167)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.BaseBundle.unparcel(BaseBundle.java:221)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:836)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1064)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1879)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.Activity.onCreate(Activity.java:995)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.support.v4.app.BaseFragmentActivityDonut.onCreate(BaseFragmentActivityDonut.java:39)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:278)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:61)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at ru.cl.cl.MainActivity.onCreate(MainActivity.java:26)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6283)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.access$900(ActivityThread.java:177) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:145) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5942) 
01-12 11:30:50.900 29951-29951/ru.cl.cl E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Artemov, 2016-01-13
@roman_art

It may be worth passing an activity to the context adapter constructor.
And it's better to pass a click listener (onClickListener) through the adapter constructor and hang it on your holder. And in the context of the fragment, launch a new activity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question