Contents

조회 수 7412 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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
번호 분류 제목 글쓴이 날짜 조회 수
1057 Develop [ios] 카메라 사용 권한 확인해서 분기하는 방법 hooni 2015.02.26 2880
1056 Database [mysql] MySQL 백업 및 복구 hooni 2019.11.22 2882
1055 PPT [ppt] OCB기술개발팀 OJT 자료 file hooni 2015.11.13 2920
1054 Develop [ios] GPS 이용 상태 확인 hooni 2015.04.27 2925
1053 PPT [ppt] 전자금융보안론 발표/설치 자료 file hooni 2016.05.03 2954
1052 Etc 사이버보안실무 수업 메모 hooni 2017.03.30 2967
1051 System/OS [linux] CentOS 에 APM 설치하기 hooni 2015.01.02 2974
1050 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 3007
1049 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 3018
1048 Develop [Javascript][Ajax] 자바스크립트 강의 산출물 file hooni 2019.10.05 3025
1047 System/OS OpenSSL로 ROOT CA 생성 및 SSL 인증서 발급하기 hooni 2017.10.28 3039
1046 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 3041
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 ... 99 Next
/ 99