Intents

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


Sponsored Links
 Hi,

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.

Luka

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
explanation.



--~--~---------~--~----~------------~-------~--~----~



Intents

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


Intents

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
android.app.ActivityPendingResult 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:
--~--~---------~--~----~------------~-------~--~----~



Intents

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 !

luka



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



Intents

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


 This is my simple theory on Intents.




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?



intents

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


 --



intents

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


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



> >



intents

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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Training in US: 8-12 February 2010:  http://bignerdranch.com 



intents

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: http://bignerdranch.com 



intents

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:

 http://github.com/commonsguy/cw-advandroid/tree/master/AdvServices/RemoteService/ 
 http://github.com/commonsguy/cw-advandroid/tree/master/AdvServices/RemoteClient/ 

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:

 http://github.com/commonsguy/cw-advandroid/tree/master/AdvServices/RemoteServiceEx/ 
 http://github.com/commonsguy/cw-advandroid/tree/master/AdvServices/RemoteClientEx/ 

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 1.1 Available!



intents

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


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





> _Android Programming Tutorials_ Version 1.1 Available!



intents

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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

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



intents

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


 


you could use Context#sendBroadcast(Intent)

pskink



intents

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
hack...@android.com

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. How to redirect the Logs into an file.

Hi,
          I want to redirect the Logs into an file. How should i proceed
....?

-- 
Thank & Regards
Peeyush Varshney

--~--~---------~--~----~------------~-------~--~----~

2. Animation between 2 activities?

Hi there!

I program on an application where different views are arranged
horizontally, each view of screen size. The user should be able to
switch between these views using his finger. I first used the
ViewFlipper, which was great for simple layouts, but which is *way*
too slow if the layouts of the views are more complex, because all
Views are drawn.

A much better method would be to place one layout per activity and
switch between these activities using the slide in / slide out
animations.
Is something in this direction possible with Android right now? Any
recommendations or best practices?


Regards & great thanks in advance

Marc Reichelt   ||   http://www.marcreichelt.de/
--~--~---------~--~----~------------~-------~--~----~

3. Market screen shots

4. R.drawable

5. ViewFlipper with clickable items

6. CheckedTextView.isChecked

7. Custom View donot Draw in ListView