Views 7410 Votes 0 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
1033 Develop [c#] 비동기 통신 샘플 코드 ㅎㅎ file hooni 2013.04.23 24514
1032 PPT [ppt] 뚜레쥬르 온라인 마케팅 제안서 file hooni 2013.04.23 24453
1031 Develop 밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ file hooni 2013.04.23 24156
1030 Develop [js] 자바스크립트(Javascript) 코드를 동적으로 삽입하는 방법.. file hooni 2013.04.23 24072
1029 Etc 양성/음성 오류에 대한 개념 hooni 2013.04.23 23860
1028 Develop [ios] UILabel top alignㅎㅎ hooni 2013.04.23 23850
1027 Develop [ios] UIColor 지정에서 RGB define ㅎㅎ hooni 2013.04.23 23817
1026 Etc 영어공부에 도움될만한 사이트 모음 hooni 2013.05.14 23710
1025 System/OS [mac] 맥(OSX)에서 root 패스워드 설정하기 hooni 2013.04.23 23590
1024 Develop [ios] UIView에서 상위 UIViewController 가져오기 hooni 2013.09.27 23435
1023 System/OS 컴파일러 수업 자료(교재 : 컴파일러 입문) file hooni 2003.04.23 23432
1022 Develop [iphone] 화면 전환 Portrait & Landscape Mode hooni 2013.04.23 23394
1021 Develop [c] 재미있는 코딩.. file hooni 2003.04.23 23274
1020 Etc 이클립스(Eclipse) 유용한 단축키 ㅋㅋ hooni 2013.04.23 23195
1019 Etc 아두이노 관련 정보.. hooni 2013.04.23 22999
1018 PPT [ajax] 크로스 도메인(Cross Domain) 이슈 해결 방안 file hooni 2013.04.23 22956
Board Pagination Prev 1 ... 8 9 10 11 12 ... 74 Next
/ 74