Views 7439 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

?

  1. [c#] 전자금융보안론 발표/설치 자료(툴바 소스코드)

  2. XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그

  3. [io] Apple Watch, Today Extension 앱ID 설정

  4. [ios] Did UIScrollView End Scrolling?

  5. [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Swift)

  6. [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Objective-C)

  7. [js] AngularJS 란?

  8. [php] 한글 문자열 자르기 (utf-8)

  9. [c] 한글 문자열 출력

  10. [ios] NavigationController 에서 왼쪽(back) 버튼 후킹하기

  11. [ios] ViewController Push할 때 애니메이션 효과

  12. [linux] CentOS Apache 웹서버에 HTTPS 적용

  13. [c] 기막힌 정렬 코드 ㅋㄷ

  14. [ios] 상위 ViewController 가져오기

  15. [ios] 최상위 ViewController 가져오기

  16. DDay Memo 1.9.4 소스코드

Board Pagination Prev 1 5 6 7 8 9 ... 53 Next
/ 53