When my device Network Connect, execute AsyncTask. this AsyncTask is get Public Ip.
asyncTask in MainActivity (inner)
I want asyncTask result (result value is public Ip) value from another class.
How to get public ip from another class?
My source
public class MainActivity extends Activity {
static getAsyncPubIp async = new getAsyncPubIp();
public static final class getAsyncPubIp extends AsyncTask<Void, Void, String> {
String result;
TextView pubView;
@Override
public void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
try {
URL pub = new URL("get public ip domain");
BufferedReader in = new BufferedReader(new InputStreamReader(
pub.openStream()));
String strPub = in.readLine();
result = strPub;
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pubView = (TextView) activity.findViewById(R.id.ip);
pubView.setText(result);
async = null;
pubView = null;
}
}
usually, call this asynctask on another class
MainActivity.getAsyncPubIp asyncPub = new MainActivity.getAsyncPubIp();
asyncPub.execute();
but I want only asyncTask result value from another class
How to get this ?