0

I'd like to get data when startActivityForResult from non Activity, please for me some sugession.

For example:

Fragment A--> non Activity class, startActivityForResult here, and how to get data on FragmentA

FragmentA

DownloadFile files = DownLoadFile.loadFiles(getActivity)

class DownloadFile

{

public static void loadFiles()

{
Intent = new Intent(...)

startActivityForResult 

}
}
John Joe
  • 12,412
  • 16
  • 70
  • 135

2 Answers2

0

u can do a callback on FragmentA and in DownloadFile to invoke it!

Fang
  • 3,652
  • 4
  • 16
  • 30
0

onActivityResult() is a method in the class Activity. Therefore if you're not extending Activity, you can't override it

You need an Activity on order to receive the result of the action. If it is just for reuse and organisation then just call your other class from your Activity?

public class DownloadFile {
    public static void loadFiles(int requestCode, int resultCode, Intent data){
        ...
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   DownloadFile.loadFiles(requestCode,resultCode,data);
    ...
}
Rohan Lodhi
  • 1,385
  • 9
  • 24
  • Yes, I tried it, but it's not possible, as on non activity class can not call setResult or any thing about ActivityResult – Le Thanh Tan May 15 '18 at 06:37