Roger
Roger

Reputation: 6527

to launch a Dialog from a Service, should I use Activity or View?

Say I'm running a service and need to pop out a dialog. As we know, it's impossible to launch a dialog directly from a service, therefor we need to launch and activity ( or view ) and then have it launch our dialog.

The dialog, as well as the activity launching it, should NOT obstruct whatever is below it, i.e. what's on screen should not turn gray and any buttons, that are outside of the dialog, should still be clickable.

Can this be achieved with using an activity or would the activity block the view under it anyway?

If so, guess I would have to use a view... since I haven't worked with views before, what would be the right way to initialize it, so that it won't obstruct whatever is under it?

Thanks!

Upvotes: 1

Views: 125

Answers (2)

CommonsWare
CommonsWare

Reputation: 1007296

Can this be achieved with using an activity

No.

would the activity block the view under it anyway?

Yes.

If so, guess I would have to use a view

A view normally is hosted by an activity. A service cannot just create some random view and put it on the screen.

You can attempt to use a Toast with a custom View for a modeless "dialog", but I am uncertain if a service-constructed View will work with that.

Upvotes: 1

icecreamman
icecreamman

Reputation: 611

You could have it launch as an activity using the Dialog theme: http://developer.android.com/guide/topics/ui/themes.html (see heading: Apply a theme to an Activity or application)

Although, no matter what you will probably obstruct the user in some way ;-). This method should only show a minimal dialog box instead of taking up the whole screen though

Upvotes: 1

Related Questions