How to start an Activity from a Service and getting a result from it

by Menny » Fri, 12 Feb 2010 03:17:26 GMT


Sponsored Links
 Hi,
I have a Service which needs to receive data from external packages.
So, to locate the data providing external packages, I use activity-
filter and PackageManager.queryIntentActivities function to locate the
interesting packages.
Now, from each such package, I need to get a ContentProvider URI.
So I want to start the external Activity and the external activity
will return a result to my service - something like
"startActivityForResult".
The problem is that there is no way to call "startActivityForResult"
from a Service, only Activity can do that, and my project does not
have any Activity, and probably can't show UI for the user.

The bottom line:
Can anyone suggest a way to get ContentProvider URI from an external
package, while my package has only a Service?

Thanks,
Menny.

--



How to start an Activity from a Service and getting a result from it

by Dianne Hackborn » Fri, 12 Feb 2010 11:54:51 GMT


 You can't do this, nor should you.  This would pop your UI in front of the
user, disrupting whatever they are doing.  This is highly discouraged.  The
proper way to do this is to post a notification, which the user can respond
to when desired and can cause your own activity to be launched, which can
then launch the other activity.




>


Sponsored Links


How to start an Activity from a Service and getting a result from it

by Kevin Duffey » Fri, 12 Feb 2010 16:35:34 GMT


 The whole purpose of a service is to stay in the background doing something,
so not sure why you would want to display a UI in a non-UI based app. As
Dianne said, post a notification that shows up on the status bar... when the
user slides it down and clicks on it, that can launch an activity... which
can then bind to the service to pass it info if need be. I'd still argue
that would not be a good idea either. Can you elaborate on why you need some
user interaction with your service.. is it something that can't be, perhaps
set in a user preferences within an activity that the user launches the
first time (or later to change settings)?






>>



How to start an Activity from a Service and getting a result from it

by Menny » Sun, 14 Feb 2010 00:07:18 GMT


 OK. I'll be explain my needs:
I'm the author of AnySoftKeyboard (http://
softkeyboard.googlecode.com).
The reason I made this keyboard, is to provide alternative layouts in
the on-screen keyboard (e.g., Hebrew, Russian, DVORAK, etc. and of
course, qwerty).
But the keyboard APK gets bloated with all the layouts, and
dictionaries etc....
So, I wanted to move all layouts to external packages: one layout (or
several) per package.

All the data I need to create a layout are the resource IDs of the
layout, the dictionary and several other stuff, all of which can be
retrieved using a ContentProvider.
But I need the ContentProvider's URI.
So I thought that starting an Activity and getting a result from it
(startActivityForResult call) will be perfect for me.

I do not need any UI to popuup (actually, I prefer that none will), I
get need to get some data from the external package.

So, these are my needs. Anyone can suggest a way?

Thanks,
Menny





> >>



How to start an Activity from a Service and getting a result from it

by Menny » Sun, 14 Feb 2010 05:33:20 GMT


  don't know what the other ContentProviders URI are.
They can be anything, I want to release my keyboard service, and then
release layouts as I need.
This means that, somehow, the keyboard service needs to "know" which
layout packages are installed on the device, and what are the URI of
their content-providers.

I don't want to use "sharedUserId", since I want to give other
developers the option to create their own layouts.


On Feb 13, 9:36pm, Dianne Hackborn <hack...@android.com> wrote:
> > > >>



How to start an Activity from a Service and getting a result from it

by Menny » Sun, 14 Feb 2010 17:24:30 GMT


 'll look at the examples, and try that.

Thanks.

On Feb 14, 11:07am, Dianne Hackborn <hack...@android.com> wrote:
> >



How to start an Activity from a Service and getting a result from it

by jotobjects » Tue, 16 Feb 2010 08:38:00 GMT


 


Are the resources of the another application package essentially
public - can any application call Context.createPackageContext() to
get the context of a different application?

--



How to start an Activity from a Service and getting a result from it

by Matt Kanninen » Sat, 27 Mar 2010 07:23:07 GMT


 Sorry about resurrecting an old thread, but really?  All resources
from all APK's are public to all APK's at all times?

Could yall post a new blog post about how to write secure Android
applications? ;)

How about assets?  And whats the deal with the stuff that ends up in
your assets folder that you didn't put there?






--



Other Threads

1. how display pdf file from network in own activity <EOM>

Thanks in advance
Shrenik vikam.

-- 

2. Ayo share foto hasil jepretan hp Android :D

Yuk kita sharing foto jepretan dari kamera Android dan berbagi cerita di
http://kameradroid.posterous.com

Ini caranya yang diambil dari webnya:


Ini adalah website untuk menampung semua foto hasil jepretan dari hp



Semua orang bisa mengirim foto dan mereka akan disebut sebagai kontributor.



Cukup kirimkan foto jepretanmu ke p...@kameradroid.posterous.com dengan cara



Bisa gunakan aplikasi Camera 360 yang tersedia di Market dan pakai efek2



Sekarang bisa, ditunggu ya :)


-- 
Ibnu Sina
just call me Ibun
twitter: @iboen
Jual [New] Micro SD class 6 + Apps2SD Ready + Android Apps & Movies
http://bit.ly/anw5Yz

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

3. Ponsel dengan Radiasi Tertinggi - HH Android nomer 2

4. Mohon bantuan suhu2

5. ga ada aplikasi market

6. Ketahanan batt Rodri 1.8.1 di N

7. android installable