I have an activity that needs to do some stuff in the background.
When the background is done, I want it to load a new activity. I can
successfully kick off the async task and using using ViewSwitcher I
can show a nice progress dialog. However, when the user hit 'back' or
'close' from the new task, I want them to see the main screen of this
task again. So, I use the showPrevious() after I start the new
Activity, but I see the screen switch from the loading window back to
the main window BEFORE the new Acitivity is launched. How do I get it
to switch after the new activity, or when they come back from the new
activity? I tried onRestart() and onResume() but both of them seem to
give me a view of -1 that I couldn't do much with.
public class XXXActivity extends Activity implements OnClickListener {
private ViewSwitcher views = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
views = new ViewSwitcher(this);
View homeView = View.inflate(this, R.layout.home, null);
views.addView(homeView);
views.addView(View.inflate(this, R.layout.loading, null));
setContentView(views);
final Button xButton = (Button)
homeView.findViewById(R.id.button_x);
xButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.button_x:
MyAsyncTask mTask = new MyAsyncTask(this);
views.showNext();
mTask.execute();
break;
}
}
private class MyAsyncTask extends AsyncTask<String, Integer, Boolean>
{
XXXActivity parent;
public CheckScannedCouponTask( XXXActivity x ) {
parent = x;
}
@SuppressWarnings("unchecked")
@Override
protected Boolean doInBackground(String... params) {
// do lots of background stuff here
return true;
}
@Override
protected void onProgressUpdate(Integer... progress) {
// update some progress here
}
@Override
protected void onPostExecute(Boolean b) {
Intent intent = new Intent(parent,
AnotherActivity.class);
parent.startActivity(intent);
parent.views.showPrevious();
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en