Contents

Views 7423 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
1081 System/OS [android] 초간단 HTTP, POST 전송 샘플 1 file hooni 2017.02.16 6482
1080 Develop [android] 초간단 얼럿 (AlertDialog) hooni 2016.10.21 5453
1079 Develop [android] 코드에서 문자열로 Resource 가져오기 hooni 2015.07.09 5010
1078 Develop [android] 해상도 관련 팁 (dip -> pixel 변환) hooni 2013.04.23 16515
1077 Develop [android] 화면 전환(가로/세로)시 설정 hooni 2013.04.23 44369
1076 PPT [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) file hooni 2013.04.23 41484
1075 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 48496
1074 System/OS [apache2] Redirect HTTP to HTTPS file hooni 2022.02.03 4494
1073 Develop [api] 인스타그램 API Access_Token 발급 방법 (Instagram API) 3 file hooni 2018.04.05 11048
1072 Develop [api] 인스타그램에서 최신 이미지 가져오기 (Using Instagram API) 20 file hooni 2018.04.05 15811
1071 Develop [asem] CMOS 패스워드 알아내기.. 소스.. file hooni 2003.04.23 9849
1070 Develop [asp] 기본 문법과 제어문 hooni 2013.04.23 8287
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 99 Next
/ 99