- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这个问题是 How to close or stop an external app that I started in Android 中提出的建议的副产品.
我正在编写一个 Android 应用程序,它是一个工业过程的远程控制 - 该过程在与我的 Android 应用程序不断通信的 PC 上运行,有时 PC 会向 Android 发送一个 PDF 文件,然后我启动AdobeReader.apk 来显示它。当 PC 关闭图像时,我想在 Android 上关闭它。
在上面的链接中,有人告诉我,一旦启动 AdobeReader,就无法通过我的代码将其关闭。 但是 我也许可以将我的应用程序重新放在前面,这对我的目的来说同样好。但我一直没能让它发挥作用。我的应用程序的主要 Activity 是 RemoteControlActivity,我试过:
try {
Intent i = new Intent(ctx, RemoteControlActivity.class);
ctx.startActivity(i);
}
catch (ActivityNotFoundException e) {
Log.d("ShowButtons(normal)", "Hide");
}
我还尝试在 startActivity() 调用之前添加 intent.setFlags(...),并使用 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | 的各种组合 Intent .FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_FROM_BACKGROUND 运气不好。
在 list 中,remoteControlActivity 的启动模式是singleTask
在调试器中,StartActivity() 被调用而没有进入 Catch 子句,但我没有在 RemoteControlActivity 的 onRestart 或 onResume 处理程序中遇到断点。
提前致谢!
编辑:下面的答案建议使用不同的标志,所以我试了一下:
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");
}
...但运气不好 - 在调试器中它调用 startActivity,没有进入 catch block ,但没有任何反应。
进一步编辑:有人要求我提供 list ;这是主要 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>
最佳答案
Flag Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
仅在 Android 将 Activity 自身置于前端时由 Android 设置。自己设置没有任何作用。
标记 Intent.FLAG_FROM_BACKGROUND
不执行任何操作,它仅用于提供信息(表明 Activity 是由后台任务启动的)。
您需要设置 Intent.FLAG_ACTIVITY_NEW_TASK
。来自 FLAG_ACTIVITY_NEW_TASK
的文档:
When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in.
关于android - 将我的 Activity 带回顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11453724/
这个问题在这里已经有了答案: Call native javascript function that has been "erased" by the web page (1 个回答) 关闭 4
我有一个 UITableViewController。 但是当我滚动到顶部时,可以在状态栏上看到表格数据,如下所示: 我怎样才能绕过这个时刻? 最佳答案 您可以使用下一个代码段隐藏状态栏: overr
我想让一个 View 显示在另一个 View 的顶部。 这是我的 View 层次结构: 基本上我想把按钮(重新开始)放在属于 PageViewController 的 UIImageView 前面。所
这是一个代码片段 tips = sns.load_dataset("tips") g = sns.FacetGrid(tips, col = 'time') g = g.map(plt.hist, "
下面的 php 数据库查询(来自 phpMyAdmin)只将一个值(第一个或最旧的)带回 amcharts: set_no_cache(); // do whatever you wa
我正在使用 mootools 从一个元素中获取 id,但它不起作用,它返回了 id 和 null。 $$(".obj").addEvent("click",function(){ var o
从内存中,微软拿了 AppDomain离开了,这个机制已经被关闭了。 现在突然发现AppDomain回来了: Assembly System.Runtime.Extensions, Version=4
我是一名优秀的程序员,十分优秀!