Contents

Views 7410 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

Javascript를 통해 Activity의 함수를 호출할 때,

예제는 finish();를 호출해서 현재 창을 닫는다.


Using the linked page as an example, you should be able to do something like this:

WebAppInterface class

public class WebAppInterface {
    Activity mActivity;

    /** Instantiate the interface and set the activity */
    WebAppInterface(Activity activity) {
        mActivity = activity;
    }

    /** Finish activity from the web page */
    @JavascriptInterface
    public void finishActivity() {
        mActivity.finish();
    }
}


Now, in your activity you add the JS interface like this:

WebViewActivity

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");


And in your webpage, you can finish the activity by clicking a button, like this:

HTML Contents

<input type="button" value="Finish the activity now" onClick="finishActivity()" />

<script type="text/javascript">
    function finishActivity() {
        Android.finishActivity();
    }
</script>

[출처] http://stackoverflow.com/questions/20639476/calling-activity-function-from-separate-class


?

List of Articles
No. Category Subject Author Date Views
1117 Develop [api] 인스타그램 API Access_Token 발급 방법 (Instagram API) 3 file hooni 2018.04.05 11034
1116 Develop [api] 인스타그램에서 최신 이미지 가져오기 (Using Instagram API) 20 file hooni 2018.04.05 15797
1115 Develop [js] Click button copy to clipboard hooni 2018.04.05 4389
1114 Develop [php] Laravel 4. twitter bootstrap 적용하기 hooni 2018.04.05 4656
1113 System/OS How to Setup an Email Server on CentOS 7 hooni 2018.04.05 5909
1112 Develop How to Test SMTP AUTH using Telnet hooni 2018.04.05 6156
1111 Develop [python] DJI Tello 드론 코딩 (프로그래밍) 58 file hooni 2018.03.04 32587
1110 System/OS [mac] 맥에서 기본 실행 앱 변경하기 file hooni 2018.03.02 3887
1109 System/OS 콘솔에서 패스워드 걸린 zip 압축하는 명령 hooni 2018.03.02 4256
1108 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 5333
1107 Develop [php] Laravel Route에서 PC/Mobile 분기 hooni 2018.01.24 4667
1106 Develop Laravel 5 Failed opening required bootstrap/../vendor/autoload.php hooni 2018.01.24 6109
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99