Android – how do I start an activity when the main activity is running in the background?

I created an application that allows users to set whether to receive notifications when the application runs in background mode. If notifications are enabled, the activity should be started (the dialog box should be displayed on the screen)

I try to enable it by:

@Override
public void onProductsResponse(List<Product> products) {
    this.products = products;
    moboolo.setProducts(products);
    if(moboolo.getAutomaticNotificationsMode() != 0 && products.size() > 0){
        if(isRunningInBackground)
        {
            Intent intent = new Intent(this, ProductListActivity.class);
            intent.setAction(Intent.ACTION_MAIN);
            startActivity(intent);
        }
    }
    drawProducts(products);

}

This is the method of the main activity. When onpause() is executed, isrunninginbackground is set to true. When I try to debug the main application while it is running in the background

Startactivity (intent) has no effect (activity does not appear)

When the main activity is running in the background (after onpause() is called), does anyone know how to break the logic to start the activity from the main activity?

thank you.

resolvent:

You cannot force activities to be displayed from applications running in the background. The documentation says:

If your activity pauses, users may perform other actions in other applications and may not want your activity to suddenly appear on top of what they are currently performing

You should use status bar notification. This allows your application to place an icon in the status bar. Then, users can slide down the status bar drawer and click your notification to open your application and display related activities. This is the way most Android applications notify users when running in the background

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>