Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android "Best Practice" use of Intents

Tags:

android

I'm an Android newbie so I apologize if this is a dumb question . . .

Intents are essentially messaging objects that can be used to activate 3 kinds of components: Activities, Services or Applications.

Especially with regard to Activities, are intents always the preferred way to activate an Activity, despite the overhead of constructing an intent object and using the overhead of the built-in Android OS for passing it?

If the Activity in question is known by the programmer to be the only legitimate one to perform a particular activity is it ever acceptable to invoke it by some more direct means such as a direct invocation via a method call?

Thanks in advance.

like image 391
Peter Nelson Avatar asked Nov 17 '10 23:11

Peter Nelson


2 Answers

despite the overhead of constructing an intent object and using the overhead of the built-in Android OS for passing it?

The intent object is pretty simple, it is the last thing you should worry about when you think for "overhead"

direct invocation via a method call?

It just won't work out, Android is a framework it is not just a pile of classes, it is like trying to use the constructor of an Activity.

But why do you have something against the Intents, why you decided that they should be "workaround" , and not the Toast.makeText or whatever ?

like image 75
apps Avatar answered Oct 16 '22 13:10

apps


To my knowledge, and somebody please correct me if I am wrong here, the only way to start another Activity is by using an Intent.

like image 33
Fredrik Wallenius Avatar answered Oct 16 '22 14:10

Fredrik Wallenius