Android - app starts whenever Chrome starts - how is this possible?

Viewed 60

I'm working on an Android app that has a strange behaviour - it starts itself whenever Chrome starts. And it doesn't matter what page Chrome opens. I'm trying to figure out how to stop this, but have no idea how this happens.

There is nothing unusual in the Manifest and no Broadcast listeners. Also I don't see anything unusual in the Chrome settings or any extensions. It happens on a number of phones but doesn't happen on others that have the same app version.

We even tried changing the applicationId - it still happens.

In logcat I can see only this line whenever this behaviour occurs:

I ActivityManager: Start proc 9360:com.company.appthatshouldntstart/u0a269 for activity: rah

This is the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.app">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <application
        android:name=".ApplicationSpecifics"
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:excludeFromRecents="true">

        <activity
            android:name=".Activities.MainActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service
            android:name=".ServiceSocket"
            android:exported="false" />
    </application>
</manifest>

I'm wondering what other ways exist to make an app behave like this.

Any help will be much appreciated!

1 Answers

Found the problem.

The app had a faulty onDestroy() logic that called System.exit(0) which I read is a bad practice. Apparently this caused the app to crash when exiting on certain phones and Android tried to restart the app. So you end up closing the app, but it restarting. After a couple of restarts the app gives up and you think you closed it properly.

But no. When opening another app (for ex. Chrome but eventually we saw it happening with other apps also) the restarting attempts continued which gives the impression that Chrome is somehow causing the app to start.

So when the onDestroy() logic was rewritten to follow the Android best practices (mostly no System.exit(0) but also some other things) the app can now quit properly and no longer starts unexpectedly.

Related