Contents

조회 수 1163 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
745 Develop [c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일 file hooni 2013.04.23 7056
744 Develop [c++] MFC 모든 헤더와 라이브러리 설명 | [교류]Programming hooni 2013.04.23 7424
743 Develop [c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ file hooni 2013.04.23 9122
742 Develop [c++] mfc 이용한 기본적인 형변환 예제 hooni 2013.04.23 11465
741 Develop [c++] mfc 이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트 file hooni 2013.04.23 8797
740 Develop [c++] mfc 조건별 파일 검색 프로그램 소스 ㅋㅋ 19 file hooni 2013.04.23 11408
739 Develop [c++] mfc 파일 한줄씩 읽기.. ㅋㅋ hooni 2013.04.23 28534
738 Develop [c++] MFC로 만든 디렉토리/파일 파인더 file hooni 2013.04.23 9329
737 Develop [c++] mfc로 만든 부엌 수납 시스템(2D기반 설계) file hooni 2013.04.23 7268
736 Develop [c++] mfc로 만든 사용자 계정 리스트 출력(EnumUser) 프로그램 예제 file hooni 2013.04.23 7290
735 Develop [c++] mfc로 만든 월플렉스 멀티 수납 시스템(2D기반 설계) file hooni 2013.04.23 7402
734 Develop [c++] mfc로 만든 인테리어 수납 시스템(2D기반 설계) file hooni 2013.04.23 7237
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 71 Next
/ 71