如何关闭或停止,我在Android的开始外部应用程序 [英] How to close or stop an external app that I started in Android

查看:113
本文介绍了如何关闭或停止,我在Android的开始外部应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要显示一些PDF文件的应用程序。这些文件是本地的设备和装置在没有网络访问高安全性的地方使用。

直到Android的得到一些天生的能力,或库来显示PDF文件,我依靠AdobeReader.apk,我正是如此火了:

 意向书I =新意图(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(dgfile),应用程序/ PDF格式);
i.setClassName(com.adobe.reader,com.adobe.reader.AdobeReader);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
// CTX是我的主要活动的传入上下文
尝试{
    ctx.startActivity(ⅰ);
}
 赶上(ActivityNotFoundException E){//柜面安装任何浏览器
    Log.e(DG_External,无观众找到了!);
}

这完美的作品,但我做了展示之后,我想阻止它,回到我的主要应用程序。在<一本获胜的答案href=\"http://stackoverflow.com/questions/3163928/startactivityintent-and-resume-to-main-activity\">this SO质疑说,如果我用的 StartActivityForresult()的,我可以用的 finishActivity()的但我无法得到它的工作做(我不吨看到它如何可以工作,因为没有活动的情况下,我们要停止)

不过,我改变了我的StartActivity为:

 ((活动)CTX).startActivityForResult(I,33); //! // 33 =任意钢筋混凝土

这调用的Adobe阅读器就好了,但做了...

 ((活动)CTX).finishActivity(33);

......没有产生结果。我试着在try / catch语句包裹,并没有抛出的异常。

我是什么做错了,我该怎么做吧?在此先感谢!


解决方案

  

要想想这个另一种方式是我可以把我的应用程序到显示器的顶部和移动AdobeReader的背景是什么?


呼叫 startActivity()你的活动之一。东西在您的应用程序确定PC上的用户关闭文件。这东西可以叫 startActivity()

I have an app that needs to display some PDF files. The files are local to the device and the device is used in high-security locations with no web access.

Until Android gets some native ability or libraries to display a PDF file I'm relying on the AdobeReader.apk, which I fire off thusly:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(dgfile), "application/pdf");
i.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
// ctx is a passed-in Context of my main Activity
try   { 
    ctx.startActivity(i);
}
 catch (ActivityNotFoundException e)    {   // incase no viewer installed
    Log.e("DG_External", "No viewer found!");
}

This works perfectly, but after I'm done displaying I want to stop it and return to my main app. The 'winning' answer on this S.O question said if I used a StartActivityForresult() I could do it with a finishActivity() But I couldn't get it to work (I don't see how it could work since there's no instance of the Activity we want to stop)

Still, I changed my StartActivity to:

((Activity)ctx).startActivityForResult(i, 33);  //!!  // 33 = arbitrary r.c.

This invoked the Adobe reader just fine, but doing a ...

((Activity)ctx).finishActivity(33);

...produced no result. I tried wrapping it in try/catch and there were no exceptions thrown.

What am I doing wrong and how do I do this right? Thanks in advance!

解决方案

Another way to think about this is how can I bring my app to the top of the display and move AdobeReader to the background?

Call startActivity() on one of your activities. Something in your app is determining that "the user on the PC closes a document". That something can call startActivity().

这篇关于如何关闭或停止,我在Android的开始外部应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆