Develop
2016.11.15 10:23
[android] Calling activity function from separate class
Views 1153 Comment 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 •
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
1077 | Develop | [ios] UIWebView에서 로컬에 있는 html 파일 불러오기 | hooni | 2015.02.10 | 889 |
1076 | Develop | [ios] iOS 8 개발자가 우선 알아야 할 3가지 | hooni | 2014.10.02 | 898 |
1075 | PPT | [ppt] iOS 플라랩#02(2015.03.19) 발표 자료 | hooni | 2015.04.24 | 898 |
1074 | Etc | 수리통계학 : 표본공간과 사상-1 | hooni | 2015.04.20 | 900 |
1073 | PPT | [ppt] Equation Solving 발표 자료 (@AjaxUI랩 밋업데이 2012.02.28) | hooni | 2015.07.22 | 904 |
1072 | Develop | [js] 좋은 강연자료 & UI 자료 | hooni | 2014.10.06 | 905 |
1071 | System/OS | [virtualbox] VirtualBox에 Ubuntu 설치하기 | hooni | 2019.11.22 | 906 |
1070 | PPT | 삼성페이(Samsung Pay) 구조 | hooni | 2016.09.09 | 921 |
1069 | Develop | [android] 딜레이를 구현하기 위한 꼼수 | hooni | 2016.11.24 | 932 |
1068 | System/OS | 콘솔에서 패스워드 걸린 zip 압축하는 명령 | hooni | 2018.03.02 | 935 |
1067 | Develop | [ubuntu] 우분투 18.04에 PHP5 설치하기 | hooni | 2020.11.14 | 936 |
1066 | System/OS | [펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들 | hooni | 2020.10.15 | 941 |