Contents

조회 수 7416 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
795 Develop [php] 몽이가 준 ajax 채팅 소스 ㅋㅋ file hooni 2013.04.23 37126
794 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 36843
793 Develop 베지어 곡선(Bézier curve) 알고리즘(spline 곡선) 3 file hooni 2013.04.23 35261
792 Develop [c++] 웹폼(webform)전송과 http 파일 업로드 샘플 file hooni 2013.04.23 34991
791 Develop [js] 웹페이지에서 특정 엘리먼트 드래그, 복사, 컨텍스트메뉴, 키보드 막기 hooni 2013.11.04 34793
790 Develop [c] C로 구현한 CGI - 방명록 file hooni 2003.04.23 34458
789 Develop [js] jQuery 코드 작성시 편리한 HTML 템플릿 hooni 2013.12.17 34229
788 Develop [android] 디바이스(시뮬레이터) hosts 파일 수정하기 hooni 2013.04.23 33715
787 Develop [c] C로 구현한 CGI - 달력과 날짜계산기 file hooni 2003.04.23 33599
786 Develop [ios] 디렉토리 하하하.. hooni 2013.04.23 33514
785 Develop [js] 키보드 아스키코드(ASCII) 코드보기 hooni 2003.04.23 33411
784 Develop [ios] 소소한 팁 (Rect,Point,Path,URL 등) hooni 2013.08.08 32640
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71