Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1294 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
393 | Develop | [php] 메모장 - 웅지학원 ([c] mysql 백업프로그램 포함) | hooni | 2003.04.23 | 7020 |
392 | Develop | [js] 점점 커지는 새창.. | hooni | 2003.04.23 | 7019 |
391 | Develop | 도메인 관련 솔루션 분석할 거.. ㅋㄷ | hooni | 2013.04.23 | 7017 |
390 | Develop | [c++] 템플릿(Template) 예제 소스.. | hooni | 2013.04.23 | 6995 |
389 | Develop | [c] 소켓 프로그래밍 요약.. | hooni | 2003.04.23 | 6989 |
388 | Develop | [web] 웹 연동 프로그램 모음.. | hooni | 2013.04.23 | 6978 |
387 | Develop | [c] 단기과정[01/24] 정렬 알고리즘 | hooni | 2003.04.23 | 6972 |
386 | Develop | [c++] 트리컨트롤 스텝 2 예제.. | hooni | 2013.04.23 | 6969 |
385 | Develop | [c] 패킷 에널라이저 예제 소스(성안당) | hooni | 2013.04.23 | 6963 |
384 | Develop | 라이브러리에 대한 설명 (static & dynamic library) | hooni | 2013.04.23 | 6960 |
383 | Develop | [js] 네이버, 다음의 플레이어 스킨 | hooni | 2013.04.23 | 6958 |
382 | Develop | [c] 단기과정[01/06] sizeof, 실수표현, 메모리, 연산자 | hooni | 2003.04.23 | 6948 |