Reputation: 9
I am developing an application which will play azan at specific time, for this I have created an AsynchTask class and whenever time matches with the system time ,player starts playing. But it gives me a Null Pointer Exception because it fails to access the media player in azan.java. So what is the procedure to access the media player instance in asynchTask class so that I can play in background, though user is on another app screen,player should start playing.
Here is my Code
class azanBackground extends AsynchTask<VOID,VOID,VOID>
{
protected Void doInBackground<Void...params>{
String temp="2:50 am"
if(systemTime.equals(temp)){
azan.fplayer.start(); // I am getting a null pointer exception here
}
Upvotes: 0
Views: 470
Reputation: 5068
when your application goes into background , it can not notify you that something happen. instead you need to use service which runs in background even when your application is get in background or closed. so add your timing check logic in service and when time matches, it will start the aazaan.
Upvotes: 0
Reputation: 3122
In order for media to be played in the background of your app location when the user is interacting with it you must start a Service/Broadcast-Receiver from your application's main activity and the service/Broadcast-Receiver shall contain all the methods related to playback. To allow activity to interact with the service, a service connection is also required. In short, we need to implement a bounded service.
Start service with pending intent Like Alarm-service
Refer http://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App
Upvotes: 1