This question is a side issue of the proposal made in How to close or stop an external application that I started in Android .
I am writing an Android application that is a remote control for an industrial process - the process runs on a PC that constantly communicates with my Android application. Sometimes the PC sends the PDF file to Android, and I run AdobeReader.apk to display it. When the PC rejects the image, I want to reject it on Android.
In the link above, they told me that as soon as I started AdobeReader, I had no way to close it from my code. However, I could bring my application to the forefront, which is also good for my purposes. But I could not get it to work. The main application for my application 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 aim.setFlags (...) before calling startActivity () with various combinations of Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_FROM_BACKGROUND with no luck.
In manifest start mode for remoteControlActivity singleTask
In the debugger, StartActivity () is called without landing in the Catch clause, but I did not hit the breakpoint in the RemoteControlActivity onRestart or onResume handlers.
Thanks in advance!
EDIT: The answer below showed 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 editing : I was asked for a manifest; here is 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>