I have a javascript interface set on my DroidGap class,
mc = new MyClass(this, appView);
appView.addJavascriptInterface(mc, "MyCls");
From which i’m starting the media player
public void playAudio(String audioFile){
copyFileToDir(audioFile);
File dest = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC + "/" + audioFile + ".mp3");
Uri r = Uri.fromFile(dest);
Intent viewMediaIntent = new Intent();
viewMediaIntent.setAction(android.content.Intent.ACTION_VIEW);
viewMediaIntent.setDataAndType(r, "audio/*");
viewMediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Intent i = Intent.createChooser(viewMediaIntent, "Play Music");
mGap.startActivity(i);
}
But when i do that, when i press back, my app is not running anymore and i get sent to the home screen.
I tried setting the keepRunning to true but didn’t help much.
super.setBooleanProperty("keepRunning", true);
How can I keep it running even when I start another Activity?
Update
Now it gets weirder. The activity does not get destroyed on a nexus 7 running 4.2, on a HTC desire/Htc Bravo running 2.2 but it fails on my galaxy s3 running 4.1.2. Any ideas on how to find out why?
My issue was self inflicted. There is an option on
Settings -> Developer Options -> Appscalleddo not keep activities. And it destroys every activity as soon as the user leaves it. So once I unticked that lovely checkbox, my problem was solved.