Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 7410 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
145 | Develop |
[c#] 비동기 통신 샘플 코드 ㅎㅎ
![]() |
hooni | 2013.04.23 | 24514 |
144 | Algorithm | 러시아 페인트공 알고리즘에 대해.. | hooni | 2013.04.23 | 24517 |
143 | Develop |
[pdf] GPS의 동작 원리 ㅎㅎ
![]() |
hooni | 2013.04.23 | 24582 |
142 | Algorithm | Polynomial time 이란? ㅋㅋ | hooni | 2013.04.23 | 24648 |
141 | Develop |
GCM 사용하기 2 (단말에 GCM 구현하기)
![]() |
hooni | 2013.07.06 | 24652 |
140 | Etc | [ios] 아이폰 개발 따라하기 ㅋㅋㅋ | hooni | 2013.04.23 | 24724 |
139 | Develop |
[c] 다중연결 서버 만들기 #4 - thread 사용
![]() |
hooni | 2013.04.23 | 24728 |
138 | Etc | [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다 | hooni | 2013.08.16 | 24734 |
137 | PPT |
[doc] 정보보호이론 강의자료 (중앙대꺼..)
2 ![]() |
hooni | 2013.04.23 | 24839 |
136 | Etc |
영어. 외우면 도움되는 필수영어회화 표현
![]() |
hooni | 2013.09.09 | 24921 |
135 | Develop |
[c++] MD5 구현 소스.. 퍼움..
![]() |
hooni | 2013.04.23 | 25108 |
134 | Develop |
[ios] 아이폰 개발 총정리..
![]() |
hooni | 2013.04.23 | 25118 |