How do I change the value in EventHandler before onCreate?

Asked 2 years ago, Updated 2 years ago, 120 views

I would like to change the value of uri according to the conditions before displaying WebView on Android.

 override fun onCreate (savedInstanceState: Bundle?) {

        super<DefaultActivity>.onCreate(savedInstanceState)
        setContentView(R.layout.activity_webview)

        setupUri()

        if(savedInstanceState==null){

            val newFragment=WebViewFragment.newFragment(uri!!)

            getFragmentManager()
                    .beginTransaction()
                    .add(R.id.web_view_container, newFragment)
                    .commit()

        }

        getSupportActionBar().hide()

    }

}

Here's what happened for iOS.

 - (void) viewDidLoad
{
    superviewDidLoad;
    
    [self registerEventHandlers: [self preferredEventhandlers]];
}

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Call ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

override func preferredEventhandlers()->[AnyObject]!{
        
        return [
            LSGAdEventHandler (webViewController:self),
            LSGLoginPageEventHandler (webViewController:self),
            LSGOtherEventHandler (webViewController:self)
        ]
        
    }

I think this is the process of running EventHandler before drawing the screen in viewDidLoad, but is onCreate applicable?

java android kotlin

2022-09-30 18:41

1 Answers

The purpose is to hook url before loading, and if create does not run, webview will not be generated and the question itself was wrong.

Use the method onPageStarted that webview has to run EventHandler.

This post was posted as a community wiki based on @hai123's comments.


2022-09-30 18:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.