Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 7412 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1033 | System/OS |
[mac] OS X 요세미티 사용자가 많이 겪는 버그와 몇몇 불편사항
![]() |
hooni | 2015.01.04 | 3266 |
1032 | Develop | [ubuntu] 우분투 18.04에 PHP5 설치하기 | hooni | 2020.11.14 | 3266 |
1031 | Develop |
[c#] 툴바 소스.. 개인적으로 만드는거..
![]() |
hooni | 2013.04.23 | 3304 |
1030 | System/OS |
Ubuntu Desktop RDP Setup - 24.04 LTS
![]() |
hooni | 2024.10.16 | 3322 |
1029 | Develop | [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기 | hooni | 2018.10.19 | 3329 |
1028 | System/OS |
[mac] VirtualBox 실행 스크립트와 bash_profile 설정
![]() |
hooni | 2020.07.08 | 3339 |
1027 | System/OS |
[펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들
![]() |
hooni | 2020.10.15 | 3346 |
1026 | Etc |
RSVP 란?
![]() |
hooni | 2017.11.22 | 3379 |
1025 | Develop | [ios] GMT Date와 Local Date 변환하기 | hooni | 2015.04.07 | 3381 |
1024 | System/OS | 개인적으로 쓰고 있는 zshrc 파일 | hooni | 2022.02.25 | 3400 |
1023 | Develop |
[ios] 카테고리 확장 메소드를 찾지 못하는 경우
![]() |
hooni | 2014.08.08 | 3446 |
1022 | Develop | [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) | hooni | 2017.12.14 | 3459 |