Contents

조회 수 1161 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
1077 PPT [ppt] iOS 플라랩#02(2015.03.19) 발표 자료 file hooni 2015.04.24 904
1076 System/OS 맥에서 포트 확인하고 닫기 (mac) hooni 2022.03.22 904
1075 Etc 수리통계학 : 표본공간과 사상-1 hooni 2015.04.20 905
1074 Develop [ios] iOS 8 개발자가 우선 알아야 할 3가지 file hooni 2014.10.02 907
1073 Develop [js] 좋은 강연자료 & UI 자료 hooni 2014.10.06 912
1072 System/OS [virtualbox] VirtualBox에 Ubuntu 설치하기 file hooni 2019.11.22 914
1071 PPT [ppt] Equation Solving 발표 자료 (@AjaxUI랩 밋업데이 2012.02.28) file hooni 2015.07.22 916
1070 PPT 삼성페이(Samsung Pay) 구조 file hooni 2016.09.09 932
1069 Develop [android] 딜레이를 구현하기 위한 꼼수 hooni 2016.11.24 941
1068 System/OS 콘솔에서 패스워드 걸린 zip 압축하는 명령 hooni 2018.03.02 950
1067 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 950
1066 System/OS [펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들 file hooni 2020.10.15 951
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 98 Next
/ 98