9

After the most recent update of the Android app, when I click on some code blocks, the app crashes.

I still don't know for sure why this happens. Stack Overflow code blocks work perfectly while others crash the app.

  • 1
    Repro'd once on Nexus 5, Lollipop 5.1, either latest version of SE app or 1 version before (forgot the timing). – Meta Andrew T. May 4 '15 at 5:15
  • Which android version are you using? – Abhishek May 4 '15 at 13:04
  • @Abhishek android version 4.4.2 – Mhmd May 4 '15 at 14:35
  • 1
    This is my fault. The fix for this bug requires a check for the current site, and for some reason there's an intentional exception when asking for a site when transitioning. Working on a fix. – Brian Nickel May 12 '15 at 0:38
3

This will be fixed in the next build. I screwed things up big time.

The Android app has a global context that exposes things like the current activity, its site, toolbar, etc. When I added support for site-specific default code highlighting I took advantage of this:

    private String getPrettifyHintFromTags(String[] tags) {
        if (tags == null)
            return null;

        for (String tag : tags) {
            if (PrettifyHinter.containsTag(tag))
                    return PrettifyHinter.get(tag);
        }

        if (PrettifyHinter.containsSite(Current.getCurrentSite()))
            return PrettifyHinter.get(Current.getCurrentSite());

        return null;
    }

What I didn't realize was that A) getCurrentSite will throw an exception if there is no current activity:

Activity act = getCurrentActivity();
if (act == null)
    throw new RuntimeException("getCurrentSite() can only be called when an activity is in the resumed state");

B) there is no activity between when the current activity gets onPause and the new activity gets onResume, C) things that happen between those two points include the new activity's onCreate and onStart calls.

With all these factors put together, the following sequence of events occurred:

  1. You tapped the code block.
  2. The question activity started an activity with the code popup intent.
  3. The question activity was suspended, setting currentActivity to null.
  4. The code popup activity was created, asked to prettify, found no SO tags, asked for the current site, and got an exception, crashing the app.

To mitigate this, I've changed the signature of the method to String getPrettifyHintFromTags(String[], Site) and making sure the site is passed in from an appropriate point rather than reaching into the context.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .