Contents

조회 수 1138 댓글 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


?

  1. [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법

  2. 사이버보안실무 수업 메모

  3. Mac OS 에 Jenkins 설치하기 (Homebrew)

  4. [ios] 동영상 플레이어 샘플 (for PIP Player)

  5. 종합시험 관련 자료

  6. [js] Javascript로 만든 포트리스 (2010)

  7. [ios] Facebook Cache 갱신하는 함수

  8. 모바일 프로그래머가 갖추어야 할 필수 역량

  9. 무료로 HTTPS 적용하기 (Lets' Encrypt)

  10. [android] 초간단 HTTP, POST 전송 샘플

  11. Enable Safari Hidden Debug Menu in Mac OS X

  12. Enable the Develop Menu in Safari

Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 98 Next
/ 98