by WildLuka » Tue, 22 Apr 2008 20:09:43 GMT

Sponsored Links

I'm still in the process of grasping the true concept of intents.
Surely I do understand that they are events and that they can
propagate through the system.  Obviously I'm not referring to the kind
of intents used to fire Activities.
Now, I'm trying to develop a local service, which one day I'd like to
turn into a remote service, which is an abstraction of a xmpp chat
library.  First of all, can I use intents to loosely propagate
exceptions, or rather exceptional events ? Imagine a login function
located in a service that instead of throwing an exception or
returning nothing, uses an intent to communicate to a LoginDialog that
either the operation was successful or the exact opposite.  Or how
does a service

I might have totally misunderstood the true intent of intents ! ( pan
intended this time ! ).  is it just a means of interconnecting
applications ? Could they be used to link software components ( still
running within the same application ) as mere interface ?

I am sensing a shift in the OO paradigm.


as an afterthought, am I the only one who thinks he's missing out on
something that might dramatically improve app design ? Diane Larsen-
Freeman, an applied linguist, believes that any grammar point can be
thoroughly explained through the "form - meaning - use" formula.  ...
as I said ... just an afterthought.

ps.  I'd be grateful if you could provide examples along with your



by Dan U. » Tue, 22 Apr 2008 20:20:05 GMT

 Well, I normally think of an Intent in the same way I think of a http
request to a web server. I'm requesting to have something happen (show
me a page in the browser = go to new activity, ask the server to do
some long running processing = start service). And when I think of how
intents are used in just my application versus how they are used in
the entire system, it's maybe comparable to sending the user to one of
my application pages versus forwarding them to a different site.


Sponsored Links


by hackbod » Wed, 23 Apr 2008 00:55:20 GMT

 eah, we have used this model very successfully in some of our
services. Here's a concrete example:

Say you have a "login service" that clients can connect with to get a
cookie to access some web service. This login service maintains the
password the user has entered, and doles out to clients an opaque
cookie allowing them to do something specific with a web service under
that user.

When a client connects to the service, we want to be able to display a
login UI if the user hasn't already entered their password, but we
don't want the client to see this. So how you can structure this is
to have the call to the login service return either the cookie if it
is already logged in, or an Intent if the user needs to log in. Then
the client can either use the cookie it receives, or execute the
Intent to have the user go through the login process.

To wrap this together, you can make effective use of to make the client code simple. To
do this, the client hands an ActivityPendingResult to the service, and
the service delivers the final cookie to the app using that. If it
needs to log in, it returns to the application an Intent that has the
ActivityPendingResult in its extras, so when the user finishes logging
in it can at that point deliver the cookie. With these in place, a
small bit of client-side code will give you a single method the
application can call to get a cookie, which asynchronously delivers
the result to the application when it is available.

One of the nice things about doing this is that the UI displayed by
the login service is actually running as part of the application, even
though it is owned by the service. Since the app is the one that
starts its activity, that UI is associated with the app, and z-ordered
with it when the app moves to the background, instead of it being some
pop-up window on the screen that is disjoint from the application it
effectively came from.

Note that an upcoming release will have a new PendingIntent API that
subsumes and greatly extends the existing ActivityPendingResult class,
and addresses some huge security holes related to passing raw Intent
objects around. In particular, it allows one application to make a
PendingIntent for an operation to be performed (start an activity,
send a broadcast, start a service, deliver a pending result), that can
safely be given to another application. It can enforce what parts of
the intent can be modified before it is sent, and when it is sent it
is sent with the privileges of the original application.

On Apr 22, 1:09pm, WildLuka <[EMAIL PROTECTED]> wrote:


by WildLuka » Wed, 23 Apr 2008 15:27:53 GMT

 o HackBod
Wow, I must say that it's impressive. Thank you for your time.
However there are a couple things I'm clear about. you refer to the
UI displayed by the service, would this be a LoginDialog ? if so, I
thought that services were not meant to interact with the user. One
more thing, a webservice or an IMservice, as in my case, carry lots of
"responsabilities " with them. I can't think one long Service class.
you talk about a "login service", but that would be just one of the
many. For instance, chat listeners, subscription request listeners.
Do you create services for those too ? I am asking this because, I
find myself defining classes that belong to the domain but neither
extend Service or Activity and therefore are out of the loop, which i
believe makes things harder to code.

Thanks again !


On Apr 23, 2:55 am, hackbod <[EMAIL PROTECTED]> wrote:


by jtaylor » Thu, 24 Apr 2008 01:14:37 GMT

 This is my simple theory on Intents.


by dane131 » Sat, 09 Jan 2010 06:43:14 GMT

 i have two applications A and B (in different packages,but it doesn't
matter).Application B is an sms application that i have made and
contains one activity.This activity has a method called sendSMS(String
number,String text).I want to call this method from application A and
send an SMS without opening the activity(the GUI) of application B but
just send an SMS in the background by calling just the method of the
activity.Any ideas?


by Jason Proctor » Sat, 09 Jan 2010 06:46:19 GMT



by dane131 » Sat, 09 Jan 2010 06:50:00 GMT

 well i want the GUI as order to function as a proper sms
application but i also want to use its functionality without raising
the GUI

> >


by Mark Murphy » Sat, 09 Jan 2010 06:52:33 GMT


Then split it into a Service (with an AIDL-exposed API) and your current
set of activities.

Mark Murphy (a Commons Guy)  | 

Android Training in US: 8-12 February 2010: 


by dane131 » Sat, 09 Jan 2010 06:56:47 GMT

 how can i do that?can you give link/s ?

> Android Training in US: 8-12 February 2010: 


by Mark Murphy » Sat, 09 Jan 2010 07:06:59 GMT


Here are sample projects demonstrating an AIDL API in a service and a
separate project accessing that API: 

Here is a slight revision of that same pair of projects, implementing an
AIDL-based callback, so the service can communicate back to the client: 

Mark Murphy (a Commons Guy)  | 

_Android Programming Tutorials_ Version 1.1 Available!


by dane131 » Sat, 09 Jan 2010 07:16:00 GMT

 ok i will check it there an easier way than that??

> _Android Programming Tutorials_ Version 1.1 Available!


by Mark Murphy » Sat, 09 Jan 2010 07:23:31 GMT


There is precisely one way to do this literally, and that's to expose an
AIDL interface from Application B. And even that's not strictly
"literally", since the AIDL interface in Application B will need to be
implemented by a service, not an activity.

The problem is that you have already decided your technical
implementation (see quoted sentence above) and are forcing us to try to
give you solutions to this narrow implementation. If you are not certain
that this is the correct implementation, then I suggest that you
describe a technical *goal* and seek advice for how to implement the goal.

Mark Murphy (a Commons Guy)  | 

Warescription: Three Android Books, Plus Updates, $35/Year


by skink » Sat, 09 Jan 2010 19:36:32 GMT


you could use Context#sendBroadcast(Intent)



by Dianne Hackborn » Sun, 10 Jan 2010 05:46:50 GMT


Yeah if the work it is to do is short (not blocking for network or UI or
whatever), this works well and can also supply a result through the version
of sendBroadcast() that returns the result when done.

You can also use startService() to send a command to a service without
needing an aidl interface...  though here getting a result back is a little
more tricky.  It can be accomplished by including a PendingIntent in the
startService() intent extras, but at that point it is probably easier to
bite the bullet and make a real aidl interface.

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

Other Threads

1. ListView and Selectors

Hey Guys,

After going through a bunch of posts here I've got a List Activity
with a pair of custom selectors that do the alternating row background
thing while maintaining the default selector behavior! The trick was
figuring out that in the selector, you had to fire a shape in there
instead of a plain android:background tag!

Looking to further extend the function, I was wondering if there is a
way to get the same sort of long-press/fading effect that the default
Google Applications have. For instance, when you long press an SMS in
the Messaging application, it kinda fades from the orange to white. Is
that possible to implement in a standardized fashion?

Thanks for any tips!


2. Problem with Preference - OutOfMemory Error

Hello All,

I am getting some strange problem.

I am having one

class ABC extends PreferenceCategory .. and this ABC class is added in
preference xml and drawing the UI from that XML.

Now based on events i am adding and removing the children Preference from
the PreferenceCategory(ABC).


ABC abc = new ABC(); // this is PreferenceCategory

// based on events
Preference myPref = new Preference();

this all works fine. But when i added my class which is extending the
Preference .


public* *class* MyClass *extends* Preference{

*public* MyClass(Context context) {

*             super*(context);



and code is same just object changed
*Preference myPref = new MyClass();*
*// based on events*

And i will get *out of memory error* after some time.  This sound stupid but
it is true. Now *in case of MyClass if i use CheckBoxPreference* *as it is
extending Preference i am not getting error and there is no VM Heap size
grow while running the apps*. So what is wrong with *MyClass . i am not
doing any special things in that.*

/ Vanraj


3. How to customize focus navigation in a ViewGroup

4. sleep & wakeup is not always right

5. Why force java 1.5?

6. Is arm-eabi-gcc support iwmmxt?

7. is it possible to display a multi column list ?