Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inactivity crash #1

Open
alirahimpour89 opened this issue May 14, 2014 · 3 comments
Open

Inactivity crash #1

alirahimpour89 opened this issue May 14, 2014 · 3 comments

Comments

@alirahimpour89
Copy link

After leaving the app in the background for a long while, you will get a crash when changing tab and and the header wont scroll...

@3mph4515
Copy link

Yeah, also got the same issue:
Here is problem, just NPE
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kmshack.newsstand/com.kmshack.newsstand.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.kmshack.newsstand.ScrollTabHolder.adjustScroll(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.kmshack.newsstand.ScrollTabHolder.adjustScroll(int)' on a null object reference
at com.kmshack.newsstand.MainActivity.onPageSelected(MainActivity.java:96)
at com.astuetz.PagerSlidingTabStrip$PageListener.onPageSelected(PagerSlidingTabStrip.java:385)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:543)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:509)
at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1282)
at android.view.View.dispatchRestoreInstanceState(View.java:12799)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2637)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2643)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2643)
at android.view.View.restoreHierarchyState(View.java:12777)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1744)
at android.app.Activity.onRestoreInstanceState(Activity.java:944)
at android.app.Activity.performRestoreInstanceState(Activity.java:916)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1138)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

@noxius
Copy link

noxius commented Oct 11, 2014

how did you fix it?

@aman400
Copy link

aman400 commented Mar 3, 2015

I had same problem.. The reason of the problem is that, Android system start killing activities whenever there is shortage of memory, you need to save your data in onSavedInstanceState() and restore it whenever Activity/Fragment is recreated, either in onCreate or onRestoreInstanceState()..

The reason why your application crashed is that, mScrollTabHolders contains SparseArrayCompat of fragments which is not saved in onSavedInstanceState() so after restore it turns out to be null and your application throws a null pointer exception..

In order to fix this crash Instead of using an activity for ViewPager, I used activity with a fragment and moved viewPager to that fragment.
In any case main activity gets killed, Fragment inside activity is also recreated and viewPager is regenerated so mScrollTabHolders never gets nulled...

Make sure you save your data in onSavedInstanceState() for recreating your fragment..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants