Surjya Narayana Padhi
Surjya Narayana Padhi

Reputation: 7841

How to use a abstract method in a class in my android activity?

I am always bad in java. Could please give me any idea about the following situation?

I have a standalone java class which has an abstract method. Code as follows

public class MyLocation{

public boolean getLocation(Context context, LocationResult result)
{
-----------------------------------
Some code here
-----------------------------------
}

public static abstract class LocationResult{
        public abstract void gotLocation(Location location);
    }
}

Now I have to use the above class in my activity to get the location. I am not sure how to use this to get the current location by using the above class. Please help me. It will be better if you can provide some example code. I am not able to understand the abstract things in java.

Upvotes: 1

Views: 6915

Answers (1)

Oscar Gomez
Oscar Gomez

Reputation: 18488

You have to extend the LocationResult class like this:

MyClass extends `LocationResult`

And then implement the abstract method:

 public abstract void gotLocation(Location location)
{
   //Do something with your result
   Location locationResult = location;
}

Or alternatively create an anonymous inner class, but since you are new to Java the above method is easier.

Upvotes: 2

Related Questions