Contents

Views 1153 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
1053 Develop [vb] 비주얼 베이직 자격증용 ㅎㅎ hooni 2003.04.23 61375
1052 Develop [vb] 비주얼 베이직 순위 정렬 루틴 hooni 2003.04.23 58316
1051 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56037
1050 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54802
1049 Develop [vb] 비주얼 베이직 141페이지 hooni 2003.04.23 58904
1048 Develop [vb] 비주얼 베이직 131페이지 hooni 2003.04.23 58043
1047 Develop [vb] 문자열에서 태그 제거함수 (Visual Basic) file hooni 2013.04.23 22621
1046 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 8185
1045 Develop [vbs] CD롬 뱉는 스크립트.. hooni 2003.04.23 11699
1044 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 11247
1043 System/OS [unix] 유닉스 csh에서 환경변수 등록 hooni 2003.04.23 11697
1042 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 14949
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 ... 98 Next
/ 98