Contents

Views 1165 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
241 Develop [ios] 한샘 카달로그 앱 소스 (아이폰용) secret hooni 2013.04.23 10922
240 Develop [c] 소수 구하기 #2 (입력한 숫자가 소수인지 판별하기..) hooni 2013.04.23 10990
239 Develop [c] 네트워크 트래릭 모니터링.. 졸업작품.. 2 file hooni 2013.04.23 11051
238 Develop [자료구조] 트리(tree) 용어정리 file hooni 2003.04.23 11071
237 Develop [c++] SetWindowPos함수를 이용한 크기조절 예제 1 file hooni 2013.04.23 11087
236 Develop [iphone] 파일 업로드 샘플 코드 ㅎㅎ secret hooni 2013.04.23 11120
235 Develop [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 file hooni 2003.04.23 11155
234 Develop [c] 최대공약수, 최소공배수, 서로소 구하기 (펌) hooni 2013.04.23 11163
233 Develop [c] 파일입출력 간단한 설명 hooni 2003.04.23 11245
232 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 11256
231 Develop [switch] 시스코 스위치(catalyst 2950) telnet 설정 hooni 2013.04.23 11272
230 Develop [ios] iOS In App Purchase 코드 부분 샘플 2 hooni 2013.11.20 11286
Board Pagination Prev 1 ... 46 47 48 49 50 51 52 53 54 55 ... 71 Next
/ 71