The Emulator I am using is Galaxy Nexus API 22, and my background music(mp3) works perfectly on it and running as a service. However, it does not work on my SUMSUNG Galaxy Note, which has API 16, I don't think it is a API-related problem though.
Am i need to write some<uses-permission .../>
in Manifest? or other solutions.
Thank you in advance!!
Here is the problem
Context context = getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
if (!taskInfo.isEmpty()) {
ComponentName topActivity = taskInfo.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
SoundService.pauseSound();
Toast.makeText(WelcomePage.this, "YOU LEFT YOUR APP", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(WelcomePage.this, "YOU SWITCHED ACTIVITIES WITHIN YOUR APP", Toast.LENGTH_SHORT).show();
}
}
I used these code in the onPause()
in WelcomePage
Activity (which is the 'MainActivity' in my App) in order to pause the background music when I press the HOME key or whatever.But I found the Toast sometimes immediately shows "YOU LEFT YOUR APP"
when this Activity shows up without do anything, so I think these piece of code is where the problem is. Can anyone help me?
Thank you!!