1

I have a class called TouchImageView extends ImageView and I detect where the user clicks on it. If it is a interest point, I want to call a method on the Detailed_Image_Activity that will update a WebView. How can I achieve this?

I found some ideas about using observer and observables but I don't know how to do that. I found this solution Equivalent of iOS NSNotificationCenter in Android? but I can't make it work it

This is my code in the TouchImageView class...

switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if(isPointOfInterest) {
            //The code below is used to update the WebView
            //The task called below exists in the Detailed_Image_Activity
            DownloadHighlightBackground HighlightDownloaderTask = new DownloadHighlightBackground();
            HighlightDownloaderTask.execute(new String[] { arg1.toString() });
        }
}
Community
  • 1
  • 1
  • This could potentially help: http://developer.android.com/reference/android/content/BroadcastReceiver.html – AJcodez Jun 06 '12 at 20:13

2 Answers2

0

To start up an activity you need access to the application's context and then you can call startActivity.

Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
  • But the activity is already started and exists, this is the problem. I just need to call a method of it. :/ – Natan Facchin Jun 06 '12 at 20:01
  • Sounds like your not doing something correctly because your not suppose to just assume that Activities are running. A quick dirty fix would be to make the function a public static. If your not able todo then you need to open up an interface somehow. Sounds like you might be able to extend Application because your able to assume that's running. You could also save this data in a shared preference and access it throughout your program. Then you'll also be able to set listeners to be notified when it changes. – Frank Sposaro Jun 06 '12 at 20:05
0

Try this,

You can get the activity from within the view, in this way..

((MyActivity)getContext()).method_name();
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
  • I think this would work but my method is actualy an async task class inside the Activity... In Detailed_Image_Activity: private class DownloadHighlightBackground extends AsyncTask { So this is the method I want to call. – Natan Facchin Jun 08 '12 at 14:02
  • This resolved my problem, actually. I created a method to create the thread to update what I needed. Thank you very very much (: – Natan Facchin Jun 08 '12 at 17:10