I have a test app that simply plays a video when it launches, and it works as expected when I launch the app from ADT/eclipse, but when I open the app normally from the app list on my Nexus 7 it will not play the video until I rotate the tablet to horizontal… (It restarts the video anytime you change orientation, but the video will not start on its own)
Here is the code:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView video = (VideoView) findViewById(R.id.myvideo);
video.setVideoPath("/sdcard/head.3gp");
video.requestFocus();
video.start();
}
}
I have tested this with both the emulator and a Nexus 7 running Jelly Bean,
Questions:
Why does this behave differently when launched via ADT ?
Am I missing an initialization that needs to happen that ADT does for me?
It may be that the app is simply paused in the background when you run it from your device, and is therefore resuming itself rather than launching from scratch. To force the app to start up from scratch, try force-stopping the app via the Settings menu and then relaunching it.
That said, having the app resume from a paused state is an extremely common event on most devices, so you’ll want to make sure that your app behaves appropriately when users restore the app from a background state, and not just from a fresh launch.