05.01.2011 2:01, Emre A. Yavuz пишет:
Thanks Kostya,
I've actually been aware of using a callback interface reference to
solve this problem, but considering its size and importance (in what
I've been working on)
Size and importance?
I just wanted to find out whether there's a simpler way to do it or not.
A Java interface seems like a pretty simple way to me.
In fact, using interfaces to connect pieces of code provides some
important benefits:
- It reduces coupling between classes, separating behavior and
implementation dependencies;
- It creates a well-defined contract for the class using the interface;
- Provides a way to "call up" in a layered system;
- Related to the above, makes it possible to compile layers as separate
units.
and probably some others that I'm forgetting right now.
-- Kostya
Cheers,
Emre
------------------------------------------------------------------------
Date: Tue, 4 Jan 2011 17:03:53 +0300
Subject: Re: [android-developers] Calling a non-static method in an
Activity class from a non-Activity class ?
From: kmans...@gmail.com
To: android-developers@googlegroups.com
You can override onPause and onResume in your activity and keep track
of its screen time.
Another, cleaner way is to pass a callback interface reference from
your activity to "the other" class instance.
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
04.01.2011 16:49 пользователь "Emre A. Yavuz" <eayl...@hotmail.com
<mailto:eayl...@hotmail.com>> написал:
>
> Hi,
>
> This question might actually have been brought to developer's
attention here on the list before, yet I wasn't able to find a
solution after a brief search on the net.
>
> I have a method in one of my Activity classes which I would like to
call from a non-Activity class when the Activity class that the method
is a member of is active and running (e.g. in my case the Activity
class that I am refering to is in fact a ListActivity class and thus
it displays a list of items on the screen when it is running) The
problem arises when the non-Activity class, which has a Broadcast
Receiver, needs to call this method to update the list.
>
> Here are my contraints:
>
> - I can't move the method to a static class
>
> - I can make neither the Activity class nor the method just by
itself static
>
> Is there any way to retrieve the "context" for the Activity that is
currently running ? Maybe I am missing a straight forward solution
here. Any suggestions on how to proceed ?
>
> Thanks in advance,
>
> Emre
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to
android-developers@googlegroups.com
<mailto:android-developers@googlegroups.com>
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
<mailto:android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en --
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en