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
번호 분류 제목 글쓴이 날짜 조회 수
241 Develop [ios] In App Purchase 개발 hooni 2013.11.20 9270
240 Develop 이어서 작업할 내용~ secret hooni 2013.11.21 0
239 Develop [js] Closure를 이용해 캡슐화.. hooni 2013.12.16 9596
238 Develop [js] jQuery 코드 작성시 편리한 HTML 템플릿 hooni 2013.12.17 33073
237 Develop [js] jQuery 셀랙터(selector) 요약 hooni 2013.12.17 9420
236 Develop [js] jQuery 배열 루프(each) hooni 2013.12.17 9989
235 Develop [js] 객체 머지.. hooni 2013.12.17 8965
234 Develop [js] jQuery 충돌 회피 hooni 2013.12.17 38315
233 Develop [js] jQjuery $ 활용 hooni 2013.12.17 8876
232 Develop [js] 순환참조에 의한 메모리 누수 관련 file hooni 2013.12.17 10846
231 Develop [js] jQuery 치트 시트 hooni 2013.12.18 36256
230 Develop [js] 이벤트 전파 3단계 hooni 2013.12.18 9966
Board Pagination Prev 1 ... 46 47 48 49 50 51 52 53 54 55 ... 71 Next
/ 71