https://kotlinlang.org logo
#android
Title
# android
c

calidion

09/27/2023, 7:07 AM
Copy code
ActivityResultLauncher<Intent> vpnLauncher = registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
        new ActivityResultCallback<ActivityResult>() {
            @Override
            public void onActivityResult(ActivityResult result) {
                if (result.getResultCode() != Activity.RESULT_OK) {
                    app.startProxyService();
                }
            }
        });
You can see how ugly this api is: redundant, repetitive, vague to understand. Obviously It can be simplified like this: Launcher<Intent> vpnLaucher = new Launcher().onResult((Result result) { .... })
not kotlin but kotlin colored 3
🤔 1
i

Ian Lake

09/27/2023, 5:06 PM
The split between the unconditional registration and the
launch
is intentional and necessary: https://kotlinlang.slack.com/archives/C0B8M7BUY/p1694440647301139?thread_ts=1694438126.574999&amp;cid=C0B8M7BUY
c

calidion

09/27/2023, 7:30 PM
The only problem is that Android is not good designed, components' parents are not recorded, and return data can not be send back to their parents by default.
In fact there need no separate launchers.