I am developing an application in which I have a common activity, i.e. BaseActivity, I am extending it to all other activities in my application. I run few AsyncTask in BaseActivity to reflect in all other activities. My query is I need to pass values to this BaseActivity from one of my activities, say MainActivity
I tried to Class, Interface concepts, but not working for me. Suggest me, how to achieve this. If any of my reference code needed, comment it, I will post it.
EDITED
I need to pass this countvalue to BaseActivity. I cannot use Intent, because I am navigating to another activity say MainActivity2
MainActivity This is my AsyncTask code
public class AsyncHttpTask extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... params) {
Integer result = 0;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(new HttpGet(params[0]));
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 200) {
String response = streamToStringCount(httpResponse.getEntity().getContent());
parseResultCount(response);
result = 1;
} else {
result = 0;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(Integer result) {
// isRefreshing = false;
//layout.setRefreshing(false);
super.onPostExecute(result);
}
}
String streamToStringCount(InputStream stream) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
String line;
String result = "";
while ((line = bufferedReader.readLine()) != null) {
result += line;
}
if (null != stream) {
stream.close();
}
return result;
}
private void parseResultCount(String result) {
Detail_Item item;
try {
JSONObject posts = new JSONObject(result);
//rstatus1=posts.optString("count");
countValue=posts.optInt("count");
countValue1=countValue;
Log.i("countvalue", String.valueOf(countValue));
}
catch (JSONException e) {
e.printStackTrace();
}
}