Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1147 댓글 0
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
TAG •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
781 | Develop | [swift] 실행시간 측정하기 | hooni | 2021.09.14 | 663 |
780 | Develop | [swift] UIView에서 subview 찾기 | hooni | 2022.12.09 | 1383 |
779 | Develop | [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 | hooni | 2021.01.29 | 1371 |
778 | Develop | [swift] NotificationCenter 간단 예제 | hooni | 2021.01.27 | 8101 |
777 | Develop | [spring] 스프링 IoC/DI | hooni | 2013.04.23 | 11345 |
776 | Develop | [sh] 쉘스크립트 if 비교 연산 | hooni | 2020.05.26 | 59071 |
775 | Develop | [sh] html 안에 있는 img 다운 받는 쉘 스크립트 | hooni | 2020.05.26 | 627 |
774 | Develop | [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) | hooni | 2019.12.06 | 1678 |
773 | Develop | [python] 파이썬 공부하는 사이트~ | hooni | 2013.11.12 | 10829 |
772 | Develop | [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) | hooni | 2019.11.22 | 1543 |
771 | Develop | [python] 애니팡, 캔디팡 매크로 | hooni | 2013.09.06 | 17291 |
770 | Develop | [python] DJI Tello 드론 코딩 (프로그래밍) 58 | hooni | 2018.03.04 | 25721 |