Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

android - Launching Dialog from Service

I want to launch a dialog from a service that hovers over whatever the user is currently looking at. The dialog gets launched like this: service gets trigger to open dialog > start transparent activity > transparent activity shows dialog.

My problem is when the user opens the app, launches into the main menu, and then presses HOME to leave. By pressing HOME, it leaves the main menu activity on pause, not destroyed, and when the service starts the dialog, the main menu gets shown underneath the transparent activity; causing the dialog to loose the affect of hovering over whatever the user is looking at.

How can make it so that the transparent activity gets opened independently of any other activities in the app? The only way to prevent this currently is to finish all the activities when they are paused; but this is impractical.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is the last thing we want. :-)

1. Dialog boxes from Services

One of the best experiences in mobile devices, IMHO, and Android in particular, is that after decades, we got rid of system-wide, pesky alert dialogs. Finally, best practices [1, 2] for user interaction gave us a way to avoid the infamous disseminate use of MessageBox(hwnd, lpText, lpCaption, uType), competing for focus and for the attention of the poor user. See video parody above.

The reason it feels awkward to start a dialog from a Service is exactly because it is supposed to be a background task, without user interaction. By concept, you shouldn't be doing this. That's the reason why we see these tricks (transparent activities, what a silly thing) to cheat the design guidelines in the first place. They are bad, they disrupt the user experience, they steal focus and attention. They disrupt our work.

2. Use notifications instead

Whenever you want to notify a user of something from the background, when the user is somewhere else, you use a notification. It's the default pattern, and it doesn't bother the user.

Therefore, you should be sending notifications from your Service.

From there, if the user is interested, then he will touch the notification and you start your own activity, possibly resuming your activity, creating a new one, and then using a dialog requesting action to be performed, or whatever you want to do.

3. Finally, do NOT use FLAG_ACTIVITY_MULTIPLE_TASK

You should not, ever, use this flag unless you have carefully read and fully understood the documentation, and the implications of using that flag.

Do not use this flag unless you are implementing your own top-level application launcher. (...) Because the default system does not include graphical task management, you should not use this flag unless you provide some way for a user to return back to the tasks you have launched.

Really. In this case, just don't.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...