when I try to close the application with my close button, the first instance of my application is closed but not the second one
there is only one instance of your Application
, and two or more instances of your main Activity
.
I guess you know the difference between activity and application, but I think it's important to mention it...
you can avoid adding to the activity stack additional instances of the same activity by providing in the manifest to the activity's element launch mode attribute.
for example, providing android:launchMode="singleInstance"
according to the documentation, insures only one instance of your activity can be created. trying starting same activity on top of already existing one - will simply won't change anything in the activity stack, but just invoke the onNewIntent()
activity callback on the already existing activity instance.