Search code examples
androidandroid-activitybroadcastreceiver

Start the wrong activity in Android project


I have 2 app and they will communicate with each other with 3rd push notification SDK.

Step1: in APP1 activity A(MAIN and launcher)->start activity B(this.finish() in A)->Press Home Button

Step2: in APP2 send msg to APP1 with SDK

Step3(): in APP1: activity A start in APP1 and msg was received in receiver of APP1.

    <activity
        android:name=".ActivityA"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize|stateVisible" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

My question: Why Activity A was Launched?

But ActivityA was not started When I send msg to APP1 with the test web page of SDK.


Solution

  • Because of your notification. As an example, this is a behaviour similar to the one in the WhatsApp app: since having the WhatsApp app continuously polling their servers for new messages is unfeasible, what they do is having their servers sending notifications to the corresponding devices when there is a new message, waking up the app in the device so it can ask the server for the new messages.

    EDIT: Your code on how you send the notification from APP2 and how you receive it in APP1 would help (you're probably doing it wrong on both sides I think).