Service Crashes With Nullpointerexception At OnCreate
i wanted to check the actual time every 5 mins in a service and mute or unmute the phone depending on the time. earlier i tried to use a while(true) with thread.sleep(300000) at th
Solution 1:
Timer myTimer = new Timer();
MyTimerTask myTimerTask= new MyTimerTask();
AudioManager audioManager;
public void onCreate()
{
super.onCreate();
audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
}
you need to initialize audioManager inside onCreate.
Solution 2:
Insted of this:
AudioManager audioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
Do this:
AudioManager audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
Post a Comment for "Service Crashes With Nullpointerexception At OnCreate"