First of all i give you a short example for my problem. Keep in mind that the wanted behavior of my app is for my own use only.
Lets say i have an app with one activity and some fragments. This app starts up through a static broadcastreceiver with an intent e.g. ACTION_POWER_CONNECTED. To this point its all fine with my implementation.
But theres a missbehavior, which i dont know how to solve right.
If the app is running and i plug my usb off and on again, a new second instance of my activity will be created with the first one still running. Just to make it clear: If i press the back button the second one disappears and the first instance shows his UI.
Im searching a way to restart my app if its already running and to start it if its not running. There is no need for saving data for any kind of reuse.
I tried some combinations with the flags FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_BROUGHT_TO_FRONT and the FLAG_ACTIVITY_CLEAR_TOP. But i think these are the wrong ones for my case. Next try was to set the Activity in the manifast to singleInstance to be sure there can be no second instance. With no great success at all.
Can anyone give me an example to solve my problem like which flags i have to use?