[android-developers] Re: How to call an Activity method from another Java class in Android
Lot of thanks friend. I spend a week for this. Thanks again. On Wednesday, 18 January 2017 14:17:39 UTC+3, Akash Arora wrote: > > ((mainactivity) getActivity()).method(parameter); > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/c4911729-1d04-448f-806b-d393905a545d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: How to call an Activity method from another Java class in Android
for you is: ((mainActivity) getActivity()). testMethod()); -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/26f5e848-6fe2-43cd-aab1-cf1ab7700838%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[android-developers] Re: How to call an Activity method from another Java class in Android
((mainactivity) getActivity()).method(parameter); -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/d5126c9d-088d-4cca-887e-d46d3ebf6f13%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [android-developers] Re: How to call an Activity method from another Java class in Android
On Sat, Jun 11, 2011 at 5:09 PM, niko20 wrote: > > 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() It depends on the lifetime of TestClass. If TestClass lives for less time than does the Activity, there's no problem. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://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 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
[android-developers] Re: How to call an Activity method from another Java class in Android
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 wrote: > On Sat, Jun 11, 2011 at 3:19 AM, Reza wrote: > > My main Activity is as below: > > > public class MainActivity extends Activity{ > > public void onCreate(){ > > TestClass mTestClass = new TestClass(this); > > } > > > 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 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