So I have a menu screen activity which calls other activities like so
option = new Intent(getApplicationContext(), OptionsScreen.class);
...
startActivity(option);
This options screen so far does nothing. more specifically, it is:
public class OptionsScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
开发者_C百科 // TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.options);
Toast.makeText(OptionsScreen.this, "options", Toast.LENGTH_SHORT).show();
}
And that's the whole activity for now. I call other Activities in a similar way. When I hit back it consistently takes 5 seconds to go back to the menu screen. This should not take this long since the OnResume() does nothing but set up onclick listeners. edit: On the MOTODEV emulators it freezes (might be a different problem) and on the basic android emulator it runs the same way as on the phone (5 second delay).
possibly relevant - When the menu screen is first called it plays a 5 second video, then uses a ViewSwitcher to go to the menu. that video only plays when the app first runs.What are some possible reasons for this delay? Any ideas would be much appreciated.
EDIT: the following is the code from the OnCreate() function which plays the video. I actually removed it and it did not fix the delay, but I'll post it anyway.
VideoView logo;
...
logo.setVideoURI(Uri.parse("android.resource://COM.PRACTICE/" + R.raw.logoanimation2));
logo.requestFocus();
logo.start();
logo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mHandler.removeCallbacks(UpdateTimeTask);
mSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcherMenu);
mSwitcher.showNext();
menushown = true;
logo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
};
});
}
});
EDIT: ok, so When I put "mSwitcher.showNext();" at the beginning of OnResume, it goes back with no delay, and plays the video again. I guess there is something I need to do to instantly show the correct view in the viewSwitcher? Anyone know what that is?
EDIT: I partially solved this problem. The delay is gone for 2/3 of the activities I launch from it. I did this in an odd way and I would still like to understand it better. I added the following code to the Onresume():
if (menushown) {mSwitcher.showNext(); mHandler.postDelayed(ViewSwitcherTask, 100);}
and then add this to the Activity Class:
Runnable ViewSwitcherTask = new Runnable() {
public void run() {
mSwitcher.showNext();
}
};
Simply calling showNext() twice did not work, and neither did anything else i tried. This is obviously not the ideal solution. Why would it work on 2/3 of my screens? Does anyone know why I had to do this? What is a better way to fix this delay?
EDIT: I simply removed the videoview from the view switcher after it plays. Fixed the problem completely.
精彩评论