Contents

Views 1155 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
1077 Develop [android] 코드에서 문자열로 Resource 가져오기 hooni 2015.07.09 3936
1076 Develop [android] 해상도 관련 팁 (dip -> pixel 변환) hooni 2013.04.23 15333
1075 Develop [android] 화면 전환(가로/세로)시 설정 hooni 2013.04.23 43371
1074 PPT [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) file hooni 2013.04.23 37851
1073 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 47516
1072 System/OS [apache2] Redirect HTTP to HTTPS file hooni 2022.02.03 680
1071 Develop [api] 인스타그램 API Access_Token 발급 방법 (Instagram API) 3 file hooni 2018.04.05 7558
1070 Develop [api] 인스타그램에서 최신 이미지 가져오기 (Using Instagram API) 20 file hooni 2018.04.05 12344
1069 Develop [asem] CMOS 패스워드 알아내기.. 소스.. file hooni 2003.04.23 8694
1068 Develop [asp] 기본 문법과 제어문 hooni 2013.04.23 7076
1067 Develop [asp] 문자열 관련 함수 요약 hooni 2013.04.23 7780
1066 Develop [asp] 문자열 넘겨받기 (get,post) hooni 2013.04.23 8679
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 98 Next
/ 98