android 调用第三方应用程序后发生什么事件?

发布于 2024-12-12 03:54:27 字数 557 浏览 0 评论 0原文

我对android有点陌生,我只是想问android调用第三方应用程序后发生了什么事件?

例如,我有以下代码打开 adobe reader 以从 sdcard 读取我的文件:

File fileToShow = new File(passedFileToShow);
Intent nextActivity = new Intent();
nextActivity.setAction(android.content.Intent.ACTION_VIEW);
nextActivity.setDataAndType(Uri.fromFile(fileToShow), "application/pdf");
nextActivity.putExtra("itemName", itemName );
startActivityForResult(nextActivity, 0);

打开 adobe reader 并且读完文件后,如何在点击设备后退按钮后调用该事件?

onBackPressed 不起作用, onActivityResult 也不起作用..

非常感谢您的帮助! :)

I'm kinda new to android, i just wanna ask android what is the event after invoking third party application?

for example i have the following code to open the adobe reader to read my file from the sdcard:

File fileToShow = new File(passedFileToShow);
Intent nextActivity = new Intent();
nextActivity.setAction(android.content.Intent.ACTION_VIEW);
nextActivity.setDataAndType(Uri.fromFile(fileToShow), "application/pdf");
nextActivity.putExtra("itemName", itemName );
startActivityForResult(nextActivity, 0);

after opening the adobe reader and i finished reading the file, how do i call the event after i tap the device back button?

onBackPressed doesn't work,
onActivityResult doesn't work too..

thanks a lot for any help! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゞ花落谁相伴 2024-12-19 03:54:27

如果您按下后退按钮,它将调用 onRestart (它还应该使用 resutlCode *Activity.RESULT_CANCELED* 调用 onActivityResult )

您可以看到整个活动生命周期 此处

if you pressed the back button, it's going to call onRestart (Also it should call onActivityResult with the resutlCode *Activity.RESULT_CANCELED*)

You can see the whole activity lifecyle here

归属感 2024-12-19 03:54:27

我要做的是定义一个布尔值来跟踪用户是否打开了 adobe。

 boolean userOpenedAdobe = false;

然后在打开 pdf 之前将其设置为 true:

File fileToShow = new File(passedFileToShow);
Intent nextActivity = new Intent();
nextActivity.setAction(android.content.Intent.ACTION_VIEW);
nextActivity.setDataAndType(Uri.fromFile(fileToShow), "application/pdf");
nextActivity.putExtra("itemName", itemName );
userOpenedAdobe = true;
startActivityForResult(nextActivity, 0);

然后您可以检查 onResume() 中的布尔值并执行某些操作。只需记住之后将其设置回 false:

protected void onResume() {
    super.onResume();
    if (userOpenedAdobe) {
        // do something
    }
    userOpenedAdobe = false;
}

What I would do is define a boolean which keeps track of if the user opened adobe.

 boolean userOpenedAdobe = false;

Then set it to true just prior to opening the pdf:

File fileToShow = new File(passedFileToShow);
Intent nextActivity = new Intent();
nextActivity.setAction(android.content.Intent.ACTION_VIEW);
nextActivity.setDataAndType(Uri.fromFile(fileToShow), "application/pdf");
nextActivity.putExtra("itemName", itemName );
userOpenedAdobe = true;
startActivityForResult(nextActivity, 0);

Then you can check the boolean in the onResume() and do something. Just remember to set it back to false afterward:

protected void onResume() {
    super.onResume();
    if (userOpenedAdobe) {
        // do something
    }
    userOpenedAdobe = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文