My friends I have a program that includes a service in which service is constantly checking received message from the server or not.
When a message is coming then service run the showMessage Activity and that the message was displayed inside that form.
The showMessage activity has 2 button as Ok and Cancel when clicked Ok then starts MainActivity ( This has two state :1-If web be In mainActivity already and coming new message, at this state do not need to start MainActivity again and only starts the showMessage actvitiy. 2- if the user program is closed because the service is run showMessage form was displayed and by press the OK button go to mainActivity form.
Now my problem in this episode. When the app is closed and the message coming and the OK button clicked and enter to my showMessage form, Since then the form will not be displayed. It's cool that I debug the lines of startActivity passes but the form does not display. In your opinion what's the problem? The reason I did not get the time of day I ask for help.
This is my showNewMessage method is MyService.class
public static void showNewMessage(boolean ShowMode) {
if (IsNewTxtMsg || ShowMode) {
IsNewTxtMsg = false;
ShowMode=false;
if (GlobalsVariabel.ShowRecievedMessageActivityIsShowing == false) {
Intent intent = new Intent(act,
ShowRecievedMessageActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PublicMethod.wakeUpScreen(act);
PublicMethod.unLockPhone(act);
act.startActivityForResult(intent, 1);
}
}
}
Note: IsNewTextMsg is the field that set to true in service when recieved new message and method showNewMessage calls with true parameter.
I solve my issue. i found that when I call start ShowRecievedMessageActivity while mainActivity is in foreground ,I do not add flag to Intent. So correct code is:
public static void showNewMessage(boolean ShowMode) {
if (IsNewTxtMsg || ShowMode) {
IsNewTxtMsg = false;
// ShowMode=false;
if (GlobalsVariabel.ShowRecievedMessageActivityIsShowing == false) {
Intent intent = new Intent(act,
ShowRecievedMessageActivity.class);
PublicMethod.wakeUpScreen(act);
PublicMethod.unLockPhone(act);
if(isMainActivityOnTop)
act.startActivityForResult(intent, 1);
else
{
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
act.startActivityForResult(intent, 1);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With