Contents

조회 수 7426 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
397 Develop [java] 스윙(swing) 인터페이스 이용해서 만든 구구단.. ㅋㅋ file hooni 2003.04.23 8177
396 Develop [ios] 동영상 플레이어 샘플 (for Remote Url) file hooni 2017.02.07 8174
395 Develop [c] 구조체/파일 입출력 프로그램 file hooni 2003.04.23 8171
394 Develop [js] 자바스크립트 메뉴얼 사이트.. ㅋㅋ hooni 2013.04.23 8170
393 Develop [c] 라인수 입력받아 마름모꼴 출력하기.. hooni 2003.04.23 8168
392 Develop [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 hooni 2013.04.23 8164
391 Develop [c] 테트리스3D (Tetris 3D) file hooni 2013.04.23 8153
390 Develop [c++] mfc로 만든 부엌 수납 시스템(2D기반 설계) file hooni 2013.04.23 8150
389 Develop [c] 단기과정[01/14] 피보나치, 파스칼.. 파일입출력 file hooni 2003.04.23 8148
388 Develop [pdf] C 국제 표준 문서 file hooni 2013.04.23 8146
387 Develop [c] 패스워드 암호화/사용자 정보 보기 file hooni 2003.04.23 8144
386 Develop [c++] 인라인 함수에 대한 설명 hooni 2013.04.23 8141
Board Pagination Prev 1 ... 61 62 63 64 65 66 67 68 69 70 ... 99 Next
/ 99