thedangler avatar image
thedangler asked thedangler edited

Launch app from Broadcast intent only brought to foreground on first call.

Hi, I'm using ACTION_PAYMENT_PROCESSED to launch my app which works perfect the first time . When the the user is finished the app closes and continues the flow (Receipt options).
However, when I use the sale app again it just skips my intent to launch my app and takes me to the receipt options page. The broadcast is received and the intent is called but nothing happens.

This gets called: I/Timeline: Timeline: Activity_launch_request id:com.example.myapp time:49747893

but continues as it nothing was there.

If I open my app on the device and close it, and try doing a sale, it works again.

Here is some code:
my broadcast receive.
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d("INTENT","intent registered");
    if (action.equals(Intents.ACTION_PAYMENT_PROCESSED)) {
        String orderId = intent.getStringExtra(Intents.EXTRA_CLOVER_ORDER_ID);
        String tender = intent.getStringExtra(Intents.EXTRA_CLOVER_TENDER_LABEL_KEY);
        String payment_uuid = intent.getStringExtra(Intents.EXTRA_CLOVER_PAYMENT_ID);

        Bundle b = new Bundle();

        Intent i = new Intent(context,QuestionActivity.class);
part of the manifest.
    android:label="Rate Me"
    <activity android:name="com.example.myapp.MainActivity"
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

<activity android:name="com.example.myapp.QuestionActivity"

I've tried looking up other android related issues and I've tried lots of solutions but nothing has worked.

Any help would be appreciated.

Clover Android SDKClover FlexIntentsBroadcastslifecycle
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jeffrey Blattman avatar image
Jeffrey Blattman answered thedangler edited
1. Include the entire logcat of the session.
2. Include "adb shell dumpsys window" to see what windows are up.

You can provide these in pastebin links.

You should understand that what you are doing will likely not work reliably. There's no guarantee on the timing of that broadcast. So for example, you could receive it, start your activity, and the normal Clover payment flow could start on top of that (I suspect that is what's happening). It's all up to the timing of many different things.

A better solution would be to raise a notification and let the merchant address your screen asynchronously to the payment flow
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

thedangler avatar image thedangler commented ·

@Jeffrey Blattman
The first launch of my app in the logcat is me running it from android studio. I close it then launch the sale app. As you can see once complete the intent fires and launches the QuestionActivity. Once its closed via a button press I try to make another sale. The broadcast fires but the activity is never launched again.


While you review this, I'll look into the notification method.

Can you point me to the documentation about triggering in app notification. I only can find references to receving a notification from an outside source.

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ thedangler commented ·

You can see in your logcat at timestamp 02-21 22:04:08.992 that the receipt activity is started around 30ms after your activity is started. So it is as I suspected. Here's Android's main page on the topic of notifications:

0 Likes 0 ·
thedangler avatar image thedangler Jeffrey Blattman ♦♦ commented ·

@Jeffrey Blattman

Ok, so why would it always work the first time around?
But never after that?

0 Likes 0 ·
Show more comments

Welcome to the
Clover Developer Community