This question is a spin-off from a suggestion made in How to close or stop an external app that I started in Android.
I'm writing an Android app which is a remote-control for an industrial process - the process runs on a PC which is in constant communication with my Android app, Occasionally the PC sends a PDF file to the Android and I launch the AdobeReader.apk to display it. When the PC dismisses the image I want to dismiss it on the Android.
In the link above I was told that once I launch the AdobeReader there's no way to shut it down from my code. However I might be able to bring my app back to the front, which is just as good for my purposes. But I haven't been able to get it to work. The main activity for my app is RemoteControlActivity and I tried:
try {
Intent i = new Intent(ctx, RemoteControlActivity.class);
ctx.startActivity(i);
}
catch (ActivityNotFoundException e) {
Log.d("ShowButtons(normal)", "Hide");
}
I also tried adding an intent.setFlags(...) before the startActivity() call with various combinations of Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_FROM_BACKGROUND with no luck.
In the manifest the launch mode for remoteControlActivity is singleTask
In the debugger the StartActivity() is called without landing in the Catch clause but I don't hit a breakpoint in RemoteControlActivity's onRestart or onResume handlers.
Thanks in advance!
EDIT: An answer, below, suggested a different flag so I tried it:
try {
Intent i = new Intent(ctx, RemoteControlActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
ctx.startActivity(i);
}
catch (ActivityNotFoundException e) {
Log.d("ShowButtons(normal)", "Hide");
}
... but no luck - in the debugger it calls startActivity, does not land in the catch block, but nothing happens.
Further Edit: I was asked for the Manifest; here's the part for the main Activity:
<activity android:launchMode="singleTask"
android:label="@string/app_name"
android:windowNoTitle="false"
android:configChanges="orientation"
android:screenOrientation="landscape"
android:name="RemoteControlActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…