Contents

Views 7410 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
73 Develop [lego] 세그웨이 이것만 볼것.. ㅎㅎ file hooni 2013.04.23 36843
72 Develop [php] 몽이가 준 ajax 채팅 소스 ㅋㅋ file hooni 2013.04.23 37125
71 Develop [js] jQuery 치트 시트 hooni 2013.12.18 37208
70 Develop [ios] iOS 6.0 이상 회전 하기 (이전 버전과 비교 변경 부분) file hooni 2014.01.27 38248
69 System/OS 맥에서 파일공유 (윈도우,맥) file hooni 2013.04.25 38343
68 System/OS [linux] 처음 설치부터 APM 설치까지 (업데이트 할 것) hooni 2013.04.23 39454
67 Develop [js] jQuery 충돌 회피 hooni 2013.12.17 39461
66 System/OS CentOS 6.5 USB 설치 6 file hooni 2013.12.18 39980
65 Develop [ios] iOS 4.0 beta 에서 3.1.3으로 다운그레이드 하는 법 file hooni 2013.04.23 41089
64 Develop [android] 개발 환경 세팅 따라하기 ㅋㅋ file hooni 2013.04.23 41188
63 PPT [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) file hooni 2013.04.23 41480
62 System/OS [mac] Mac에서 Mac으로 원격제어하기 (맥에서 맥으로) file hooni 2013.10.08 41503
Board Pagination Prev 1 ... 88 89 90 91 92 93 94 95 96 97 ... 99 Next
/ 99