I think the best way will be to use a BroadcastReceiver
to pass intent.
Check this example http://android-coding.blogspot.in/2011/11/pass-data-from-service-to-activity.html
eidt
Try to use getApplicationContext()
instead of getBaseContext()
. If this wont work try something like this :
//in your activity
private MyReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
int datapassed = bundle.getInt("DATAPASSED");
Toast.makeText(getApplicationContext(), "Broadcast received",
Toast.LENGTH_LONG).show();
cd.setText("");
showMyDialog();
volumeMax();
alternatingScreen();
}
}
}
};
@Override
public void onResume(Bundle savedInstanceState) {
IntentFilter intentFilter = new IntentFilter(SOME_ACTION);
MyReceiver mReceiver = new MyReceiver();
registerReceiver(mReceiver, intentFilter);
}
//in your service somewhere
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.putExtra("DATAPASSED", 1);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
sendBroadcast(intent);
I hope that will solve it :)