Call function after an Intent is finished
android, android-intent, java
Solution
Call `startActivityForResult()` instead of `startActivity()`. When the activity completes, you'll get a callback to your activity's `onActivityResult()` method, where you can do what you need.
See the documentation for more information.
EDIT: `RESULT_OK` is a standard result code, but activities are free to return other values greater than or equal to `RESULT_FIRST_USER`. Zero is `RESULT_CANCELED`, which usually happens when someone whacks the Back button.
Problem
I think this is a simple problem, but can't find an answer. I got this piece of code: ``` public void onButtonClick(View v) { Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(root + "/Doppen/"+ "doppen.txt"); intent.setDataAndType(Uri.fromFile(file), "text/*"); startActivityForResult(intent, 1); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, getIntent()); if(resultCode==RESULT_OK && requestCode==1){ System.out.println("RESULT :D"); } } ``` Got any idea what is wrong here? I open a text file, but after the user tapped on "Save", I want to call an other function. How to do this automatically? So how to check when user taps on "Save" or when the intent is done/finished? EDIT 1: I found a problem: When I comment `if(resultCode==RESULT_OK && requestCode==1){` then it does print the result when it is done, So I know where it goes wrong, now the why question :p EDIT 2: requestCode does prints "1", so that is good. However, resultCode prints "0", not good. EDIT 3: Found the answer, maybe also usefull for others. After I pressed Save, I use the backbutton (of the phone) to get back to the app, but that gives a resultCode of "0".