I am launching activity from the service based on some value got from the server and the activity will be displayed for the some time and after getting close instruction fro
Write a broadcast receiver in your CustomDialogActivity like following.
private final BroadcastReceiver abcd = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
finish();
}
};
Then register it in the same file like the following:
onCreate(){
registerReceiver(abcd, new IntentFilter("xyz"));
}
Unregister it in onDestroy.
onDestroy(){
//unRegister
}
Now,Whenever you want to close that Activity just call like the following.
sendBroadcast(new Intent("xyz"));
Hope this help.
Try to send broadcast using context.
context.sendBroadcast(new Intent("xyz"));
Answer from Jainal is Working for me.
You must add the receiver into the manifest for your activity, For example :
<activity android:name="MyActivity">
<intent-filter>
<action android:name="xyz" />
</intent-filter>
</activity>