My concern with ever passing an activity is now you expose yourself to
that activity memory leak problem, right? Unless you make sure to set
it to null in onDestroy()

On Jun 11, 2:11 pm, Mark Murphy <[email protected]> wrote:
> On Sat, Jun 11, 2011 at 3:19 AM, Reza <[email protected]> wrote:
> > My main Activity is as below:
>
> > public class MainActivity extends Activity{
> >   public void onCreate(){
> >        TestClass mTestClass = new TestClass(this); <br/>
> >   }
>
> >   public   testMethod(){
> >     // do some work here
> >   }
> > }
>
> > now, in my TestClass.java I receive reference to the MainActivity:
>
> > public class TestClass{
>
> >   public TestClass(Activity mActivity){
> >      mActivity.testMethod();      //Android/Java doesn't recoginze
> > testMethod here????
> >   }
> > }
>
> Of course. There is no testMethod() implemented on Activity. If you
> want to reference testMethod(), you have to pass a MainActivity to
> TestClass' constructor, not just an Activity.
>
> > I've been trying to solve this issue for a few days with no success.
>
> Since you are new to Java, I recommend you stop Android development
> for a few months and learn Java outside of Android. Trying to learn
> Java and Android at the same time will be very frustrating, as most
> Java educational resources do not deal with the things that are odd
> about Android.
>
> > P.S. The TestClass will act as a library that everyone can call it
> > from their android application. In other words, I provide the
> > TestClass as the library. The user then implements the content of a
> > method that will be executed whenver certain conditions are met. Thus,
> > I need to call that specific method (which will be defined by the user
> > in their own Activity) through a reference which is passed by the user
> > to my library class
>
> As you spend your months learning Java, I recommend that you learn
> about Java interfaces.
>
> http://en.wikipedia.org/wiki/Interface_(Java)
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training...At Your Office:http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to