View Full Version : How to call another class function in Android
uzaircs
11-13-2009, 05:40 AM
hi, Guyz
i am calling a same package class priavate function
but i am unable to call a function,,,
when i am searching on net i found that
use intent to do it ...
can any body tell me a simple exmple
how to call the function of another class...
extorian
11-13-2009, 03:15 PM
There are loads of examples on Google's Developer site, for example:
http://developer.android.com/guide/tutorials/hello-world.html
I'm assuming you don't have a background in Java, because you're using the term "function" instead of "method". You call other methods in exactly the same way as you call methods in Java.
So if the class that contains the method you want to call is called myClass, and the method is called someMethod(), you have two choices:
1) import MyClass at the top of your code and then have a line that just reads "someMethod();" to call it.
2) if they're both in the same package just call it directly with "MyClass.someMethod();".
Intents are different - among other things they're the events that are broadcast from the OS or apps. They can be picked up by the OS or apps and acted upon. So, for example, the android.provider.Telephony.SMS_RECEIVED intent is broadcast whenever a new SMS message is received. All apps that have a receiver class that say they listen out for this intent will be executed by the OS. So, you might have an app that flashes your LED a certain colour, an app like Phone Finder that will look for a password in the text message and send back the GPS co-ordinates if it's present, etc.
Also, you'll be better placed posting questions like this in the developer forum (http://androidcommunity.com/forums/f4/), not in the Android OS forum. People are better placed to help you there, and there's a load of FAQs etc you might find useful.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.