Contents

Views 7412 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
157 Etc 캘리포니아 운전면허 문제 file hooni 2017.07.22 3484
156 Develop [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) hooni 2017.12.14 3459
155 Develop [ios] 카테고리 확장 메소드를 찾지 못하는 경우 file hooni 2014.08.08 3446
154 System/OS 개인적으로 쓰고 있는 zshrc 파일 hooni 2022.02.25 3400
153 Develop [ios] GMT Date와 Local Date 변환하기 hooni 2015.04.07 3381
152 Etc RSVP 란? file hooni 2017.11.22 3379
151 System/OS [펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들 file hooni 2020.10.15 3345
150 System/OS [mac] VirtualBox 실행 스크립트와 bash_profile 설정 file hooni 2020.07.08 3339
149 Develop [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기 hooni 2018.10.19 3329
148 System/OS Ubuntu Desktop RDP Setup - 24.04 LTS file hooni 2024.10.16 3322
147 Develop [c#] 툴바 소스.. 개인적으로 만드는거.. secret hooni 2013.04.23 3304
146 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 3266
Board Pagination Prev 1 ... 81 82 83 84 85 86 87 88 89 90 ... 99 Next
/ 99