Androider
Androider

Reputation: 21335

Keeping Widget Applications Main Activity in BACKGROUND

My widget is deployed in an applications which also launches a main activity. Most of the time I want this main activity in the background but when I click on the widget it comes to the FOREGROUND and rather than the user seeing the widget change the application main activity displays. I can't get rid of the main activity because I also want to allow users to launch the application that contains the widget. Was wondering how this situation can be managed. Thanks.

Upvotes: 0

Views: 1254

Answers (3)

Androider
Androider

Reputation: 21335

Setting android:launchMode="singleInstance" seems to keep the main activity from coming to the foreground. Not sure if there might be some downsides to this however.

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006664

click on the widget it comes to the FOREGROUND and rather than the user seeing the widget change the application main activity displays.

You are the one who set up the PendingIntent to bring that activity to the foreground when something in the app widget is clicked. Fix your PendingIntent, and your problem will go away.

Here is a sample application that uses PendingIntents to update an app widget without bringing any activities to the foreground -- in fact, the application has no activities.

Upvotes: 0

Mike Yockey
Mike Yockey

Reputation: 4593

Background processes in Android should be implemented as Services. Activities are intended to exist in the foreground and will suspend themselves when made inactive.

Upvotes: 0

Related Questions