In my project i defined an interface like this:
public interface SearchResultProgressListener {
public void OnSearchCompleted(boolean value);
}
I’ve implemented this in class A (called SearchResultsActivity):
public class SearchResultsActivity extends BaseActivity implements
SearchResultProgressListener {
private ProgressBar mProgressBar;
private boolean timerStatus = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchresults);
// Linking progressbar
mProgressBar = (ProgressBar) findViewById(R.id.progressBar_fake);
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
int temp = (int) millisUntilFinished / 1000;
switch(temp) {
case 9: temp = 1; break;
case 8: temp = 2; break;
case 7: temp = 3; break;
case 6: temp = 4; break;
case 5: temp = 5; break;
case 4: temp = 6; break;
case 3: temp = 7; break;
case 2: temp = 8; break;
case 1: temp = 9; break;
case 0: temp = 10; break;
}
Log.e("Hesam", "Status1: " + timerStatus);
if(!timerStatus)
mProgressBar.setProgress(temp);
else
mProgressBar.setProgress(10);
}
public void onFinish() {
mProgressBar.setVisibility(View.GONE);
}
}.start();
}
@Override
public void OnSearchCompleted(boolean status) {
this.timerStatus = status;
Log.e("Hesam", "Status0: " + timerStatus);
}
}
I have class B (called HotelsAsyncTaskFragment) that through this class I want to send Boolean to class A.
public class HotelsAsyncTaskFragment extends SherlockFragment {
private SearchResultProgressListener srpListener;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
srpListener = (SearchResultProgressListener) new SearchResultsActivity();
}
class HotelsSearchTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {...}
@Override
protected Void doInBackground(Void... params) {...}
@Override
protected void onPostExecute(Void result) {
if(!isComplete()) {
HotelsAsyncTaskFragment.this.srpListener.OnSearchCompleted(false);
} else {
HotelsAsyncTaskFragment.this.srpListener.OnSearchCompleted(true);
}
}
}
}
Now, I expect when I setting “timerStatus” in class A to “True”, it’s content changes but it doesn’t. This is my Log:
02-13 16:41:58.716: E/Hesam(469): Status1: false
02-13 16:42:13.566: E/Hesam(469): Status1: false
02-13 16:42:14.566: E/Hesam(469): Status1: false
02-13 16:42:14.611: E/Hesam(469): Status0: true
02-13 16:42:15.571: E/Hesam(469): Status1: false
02-13 16:42:16.601: E/Hesam(469): Status1: false
02-13 16:42:17.616: E/Hesam(469): Status1: false
02-13 16:42:18.616: E/Hesam(469): Status1: false
02-13 16:42:19.621: E/Hesam(469): Status1: false
02-13 16:42:20.626: E/Hesam(469): Status1: false
02-13 16:42:21.621: E/Hesam(469): Status1: false
As you can see, “timerStatus” is set to “true” in forth line but after that I have no idea why it is set to false!!!
any suggestion would be appreciated. Thanks
You haven’t shown the code for SearchResultsActivity() but it’s clearly not the same as MainActivity(). The log entries you are seeing are coming from two different activities with two separate variables.