-2

I keep on getting this error when I try to run my app and I think it might be because I have too many activities/intents as I got the error after I included them. Still I'm unsure if this may be the problem. Also the activities for my options menu open once but when I try to open them again they don't anymore and I think this error may be the problem.

Here is my code for the intents:

MainActivity

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_home) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    } else if (id == R.id.action_eda) {
        Intent intent2 = new Intent(this, EdaInfoActivity.class);
        startActivity(intent2);
    } else if (id == R.id.action_about) {
        Intent intent3 = new Intent(this, AboutMe.class);
        startActivity(intent3);
    }

    return true;
}

and my Android Manifest

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable"/>
    </activity>
    <activity
        android:name=".NewsItemActivity"
        android:parentActivityName=".MainActivity">
    </activity>
    <activity android:name=".EdaInfoActivity">
        <intent-filter>
            <action android:name="android.intent.action.INFO"/>
        </intent-filter>
    </activity>
    <activity android:name=".AboutMe">
        <intent-filter>
            <action android:name="android.intent.action.ABOUT"/>
        </intent-filter>
    </activity>
</application>

1 Answers1

1

I think it might be because I have too many activities/intents as I got the error after I included them.

This is NOT the problem. You do not have more than one of these Activities running at once, so it isn't what is causing your error. (could be coincidence of adding in some activity that HAS the below error. (Detailed explanation in this link from Deividi Cavarzan's comment above)


The problem is that you are doing 'long running(blocking)' processing on the foreground thread.

Android has a "Looper" that a thread can have. The UI Thread has one by default, This is what processes messages and runnables via a handler. When this Looper blocks for more than 5 seconds you get an ANR (Application Not Responsive) error.

When your application takes too long within the UI Thread, but NOT that long, you can get the error above that you are getting.

You should look to see what computationally complex operation(s) you are running and -at least- run them in a AsyncTask. or run them as a runnable.


Concurrency in Android is such a complex topic that I don't even want to really touch on how to 'solve it' for you. Doug Schmidt (Full disclosure, my PhD adviser, and I helped in creating some of the examples he shows in class, etc.) has made some good videos where he lectured for his 282 Class (Systems programming (on the android platform) Where you learn concurrency & services)

Here is the playlist of those class lectures:

https://www.youtube.com/playlist?list=PLZ9NgFYEMxp4KSJPUyaQCj7x--NQ6kvcX

Community
  • 1
  • 1
mawalker
  • 2,072
  • 2
  • 22
  • 34