android调用第三方应用程序后的事件是什么?

时间:2011-10-26 10:45:54

标签: android android-intent

我对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也不起作用..

非常感谢您的帮助! :)

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

我要做的是定义一个布尔值,跟踪用户是否打开了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;
}