开发者

how to completely get rid of an activity's GUI (avoid a black screen)

I'm trying to write a very simple app that will do just one very simple non-GUI action, then display a short message (using toast, on top of what was already on the screen, e.g. home screen), and finish. That's all.

This almost works, but i'm still getting a brief black screen after the app starts, then back to home screen and things work as i intend after that. I thought that not using setContentView on my acti开发者_Go百科vity (thus depriving it of a View) would be enough to avoid the black screen, but it still pops up. Please notice that (as suggested in a related question), a service is not the answer to my problem. I just want a GUI-less (except for one toast) app that runs and ends right away. Thanks :)


In <activity> in your manifest use

android:theme="@android:style/Theme.NoDisplay"

Note this assumes you will call finish() before returning from onResume(). If you are going to do more work after that (for example if you will be doing any networking or other such thing that can't be done quickly synchronously), you will probably want to start a service to take care of the work to tell the platform your process should continue running after the activity finishes.


Sounds like a job for an IntentService. You send it an intent, and if it isn't running it starts, then it treats all received intents, then it stops. Short and simple.


a service is not the answer to my problem

Yes it is

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜