Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 7422 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1093 | System/OS |
네트워크 용어 정리
![]() |
hooni | 2022.11.20 | 4604 |
1092 | PPT |
네오웹 세미나 자료~
![]() |
hooni | 2013.05.28 | 0 |
1091 | System/OS | 나중에 해봐야지.. libconv 설치.. ㅡ,.ㅡ; | hooni | 2013.04.23 | 20223 |
1090 | Develop |
객체지향 프로그래밍에 대한 개념.. (객체)
![]() |
hooni | 2013.04.23 | 8647 |
1089 | System/OS | 개인적으로 쓰고 있는 zshrc 파일 | hooni | 2022.02.25 | 3407 |
1088 | System/OS | 개인적으로 쓰고 있는 bash_profile | hooni | 2015.01.16 | 2018 |
1087 | Etc | 개발자가 알아야할 10가지 보안팁으로 코드 보호하기 | hooni | 2013.04.23 | 17543 |
1086 | System/OS |
[펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들
![]() |
hooni | 2020.10.15 | 3355 |
1085 | Develop | [펌] 게임 엔진 만든거 공개합니다. | hooni | 2015.02.21 | 3797 |
1084 | Develop |
[자료구조] 트리(tree) 용어정리
![]() |
hooni | 2003.04.23 | 12175 |
1083 | Etc | [용어] POC, Pilot, BMT에 대한 IT 업계에서 통용되는 의미 | hooni | 2014.01.02 | 43224 |
1082 | Etc | [세미나] XML 레포트.. | hooni | 2003.04.23 | 21471 |