Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1313 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1173 | System/OS |
해커스랩 깨기.. 후후.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 18524 |
1172 | Etc |
플라스터(Plaster) 수업 내용
![]() |
hooni | 2016.05.24 | 0 |
1171 | Develop | 프로그램 문서 관리 (Doxygen) | hooni | 2013.04.23 | 16438 |
1170 | Develop |
프로그래밍에서 foo, bar 함수의 유래
![]() |
hooni | 2013.06.25 | 21475 |
1169 | Develop | 프로그래밍 소스 관련 사이트.. | hooni | 2013.04.23 | 16526 |
1168 | Develop |
페이팔에서 돈 찾기 (Paypal withdraw)
![]() |
hooni | 2014.02.20 | 11481 |
1167 | Etc | 티스토리 테이블 html,css 구문 | hooni | 2013.11.03 | 16056 |
1166 | System/OS | 콘솔에서 패스워드 걸린 zip 압축하는 명령 | hooni | 2018.03.02 | 1133 |
1165 | System/OS |
컴파일러 수업 자료(교재 : 컴파일러 입문)
![]() |
hooni | 2003.04.23 | 22073 |
1164 | Develop |
캘리포니아 운전면허 족보
![]() |
hooni | 2017.06.12 | 890 |
1163 | Etc |
캘리포니아 운전면허 문제
![]() |
hooni | 2017.07.22 | 1174 |
1162 | Develop |
최근 논문 자료 (2011/01/03, 만현형한테 보낸거..)
![]() |
hooni | 2013.04.23 | 10366 |