I have two Activity
and one Service
.I have created a service
and add actions to it in manifest
. two actions belong to firstActivity
and one action belongs to SecondActivity
. Two action
belongs to firstActivity
calls but when i call the same Service
from SecondActivity
. It doesn't even create.
Why is it so?
Calling from first Activity
Intent equalizerService = new Intent(context,
MyEqualizerService.class);
equalizerService.setAction(MyEqualizerService.ACTION_PLAY);
startService(equalizerService);
calling from Second Activity
Intent equalizerService = new Intent(context,
MyEqualizerService.class);
equalizerService.setAction(MyEqualizerService.ACTION_INIT_EQ);
startService(equalizerService);
but it doesn't startService. I don't know why.
I have properly added intent-filter like
<service
android:name="com.zare.MyEqualizerService"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="com.zare.action.PLAY" />
<action android:name="com.zare.action.PAUSE" />
<action android:name="com.zare.action.NEXT" />
<action android:name="com.zare.PREVIOUS" />
<action android:name="com.zare.INITIALIZE_EQ"/>
</intent-filter>
</service>
And onStartCommand
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Log.v("meiService", "onStartCommand");
if(intent != null && intent.getAction() != null)
{
if(intent.getAction() == ACTION_PLAY)
{
if (null != mediaPlayer && !mediaPlayer.isPlaying())
{
if(musiky!=null)
{
if(musiky.size() > 0 )
{
Music cMusic = musiky.get(currentSongIndex);
play(cMusic.getUrl());
}
}
else
{
Toast.makeText(getApplicationContext(), "No song to Play", Toast.LENGTH_LONG).show();
}
}
}
else if(intent.getAction()==ACTION_INIT_EQ)
{
if(isOurPlayerPlaying())
{
Toast.makeText(getApplicationContext(), "I am initialized", Toast.LENGTH_LONG).show();
initBassBoost(mediaPlayer.getAudioSessionId());
initEqualizer(mediaPlayer.getAudioSessionId());
initVirtualizer(mediaPlayer.getAudioSessionId());
}
else
{
Toast.makeText(getApplicationContext(), "I am initialized with 0 id", Toast.LENGTH_LONG).show();
initBassBoost(0);
initEqualizer(0);
initVirtualizer(0);
}
}
}
return START_STICKY;
}