1

I have an application in Android that has a button in the MAIN activity that performs an action.

Is there a way to execute that action without opening the application?

I don't know if I can say it is like a widget, because it does not wait for updates.

The user should be able to execute that action just clicking on the icon of the application without opening. Is it possible?

Cœur
  • 37,241
  • 25
  • 195
  • 267
mlecar
  • 729
  • 6
  • 9

2 Answers2

4

Yes and no. What I had to do for a similar problem was have a transparent view in my main activity, and then self-terminate:

In your activity...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            // Do whatever you need here...
    finish();
}

And in AndroidManifest.xml:

        <activity android:name=".whatever" android:theme="@android:
style/Theme.NoDisplay">

Hope this helps,

Phil Lello

Phil Lello
  • 8,377
  • 2
  • 25
  • 34
  • 3
    [`Theme.NoDisplay`](http://developer.android.com/reference/android/R.style.html#Theme_NoDisplay) is more appropriate. – Jake Wharton Apr 07 '11 at 04:19
  • Hi folks! The Theme.NoDisplay works like a charm! I've tried to use Service too, and that works, but I think yours solution is much better!! Thanks a lot! Sorry for late feedback!! – mlecar May 05 '11 at 02:16
0

Try this question Android - How to execute main functionality of project only by clicking on the icon of application?

Community
  • 1
  • 1
yogsma
  • 10,142
  • 31
  • 97
  • 154