Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android launches system settings instead of my app

For some reason whenever I (try to) start my app the phone decides to launch system settings instead of my "main activity". And yes, I am referring to the "Android system settings", and not something from my app.

This only happens on my phone, and I suppose it probably could be related to the fact that my app had just opened system settings when I decided to re-launch with a new version from Eclipse.

It is possible to start the app from within Eclipse, but when I navigate back from the app it returns to the system settings rather than the home screen, as if the settings activity was started first and then my activity. If I then start the app from the phone all I get is system settings yet again.

The app is listening to the VIEW-action for a specific URL substring, and when I start the app using a matching URL I get the same result as when I start it from Eclipse, app starts, but when I return I return to settings.

I have tried googling for this problem, and all I could find was something about Android saving state when an app gets killed, but without any information on how to reset this state. I have tried uninstalling the app, killing system settings, rebooting the phone, reinstalling, clearing application data.. no luck..

For what it's worth, here's the definition of my main activity from the manifest,

<activity android:name=".HomeActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:clearTaskOnLaunch="true" android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:pathPrefix="/isak-web-mobile/smart/" android:scheme="http" android:host="*"></data>
    </intent-filter>
 </activity>

And here is the logcat-line from when I try to start my app, nothing about any settings anywhere.

I/ActivityManager( 1301): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=se.opencare.isak/.HomeActivity }

When I launch from Eclipse I also get this line (as one would expect),

I/ActivityManager( 1301): Start proc se.opencare.isak for activity se.opencare.isak/.HomeActivity: pid=23068 uid=10163 gids={3003, 1007, 1015}

If it matters the phone is a HTC Desire Z running 2.2.1.

Currently, this is my HomeActivity,

public class HomeActivity extends Activity {
    public static final String TAG = "HomeActivity";

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + ")");
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate(" + savedInstanceState + ")");
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        Log.d(TAG, "onDestroy()");
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        Log.d(TAG, "onPause()");
        super.onPause();
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onPostCreate(" + savedInstanceState + ")");
        super.onPostCreate(savedInstanceState);
    }

    @Override
    protected void onPostResume() {
        Log.d(TAG, "onPostResume()");
        super.onPostResume();
    }

    @Override
    protected void onRestart() {
        Log.d(TAG, "onRestart()");
        super.onRestart();
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        Log.d(TAG, "onRestoreInstanceState(" + savedInstanceState + ")");
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    protected void onResume() {
        Log.d(TAG, "onResume()");
        super.onResume();
    }

    @Override
    protected void onStart() {
        Log.d(TAG, "onStart()");
        super.onStart();
    }

    @Override
    protected void onStop() {
        Log.d(TAG, "onStop()");
        super.onStop();
    }

    @Override
    protected void onUserLeaveHint() {
        Log.d(TAG, "onUserLeaveHint()");
        super.onUserLeaveHint();
    }
}

Nothing (of the above) is written to the log.

After reading Blundell's response I have tried changing the launchMode/clearTaskOnLaunch settings, with the following results,

  • Situation A - I remove launchMode and clearTaskOnLaunch: same problem as before
  • Situation B - I remove clearTaskOnLaunch and keeps launchMode="singleInstance": another problem
    • Open app - My HomeActivity is showing
    • Click on a button to open another activity within my app - it opens as it should
    • Click on the system back-button - it returns me to system settings
    • Click on the system back-button again - I am returned to my HomeActivity
    • Another click on the back-button brings me back to the Android home screen
  • Situation C - I remove only launchMode and keeps clearTaskOnLaunch: same problem as before
  • Sitatuion D - I remove clearTaskOnLaunch and set launchMode="singleInstance": same as situation B
like image 302
jsundin Avatar asked Mar 10 '11 15:03

jsundin


People also ask

Why won't my apps open on my Android phone?

Often apps don't launch properly due to temporary issues that get resolved by simply restarting your device. You can perform a soft reboot by long-pressing the power button and selecting Restart or swiping the app-shade down, selecting the power icon, and then choosing Restart.

What is Android system settings?

The Android System Settings menu allows you to control most aspects of your device—everything from establishing a new Wi-Fi or Bluetooth connection, to installing a third-party onscreen keyboard, to adjusting system sounds and screen brightness.

How do I change system settings on Android?

You can view these settings via the Configure apps screen. Tap on Modify system settings to proceed. The next screen shows every app installed on your phone with a message that tells you whether it can modify system settings.

Why my app is not opening?

You can usually clear an app's cache and data through your phone's Settings app. Settings can vary by phone. For more info, contact your device manufacturer. Temporarily free up space when you clear cached data.


1 Answers

You are not calling setContentView() from the HomeActivity (as per the code added by you). And when it is not present, different device behave differently, like on emulator you will see "Application not installed on your phone". Try setting content view.

like image 75
Karan Avatar answered Oct 16 '22 18:10

Karan