Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1296 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
97 | Develop | [c] 시간 관련 함수 설명과 예제.. | hooni | 2003.04.23 | 11546 |
96 | Develop | [c] 문자열 처리 관련 함수들 설명 | hooni | 2003.04.23 | 8008 |
95 | Develop | [linux] 프로세스 관련 시스템콜 | hooni | 2003.04.23 | 7865 |
94 | Develop | [c] 시간 계산 하는 프로그램 소스코드 | hooni | 2003.04.23 | 6767 |
93 | Develop | [php] 마시마로 캐릭터 방명록 | hooni | 2003.04.23 | 8265 |
92 | Develop | [c] OpenGL 색 입방체의 회전(입체) | hooni | 2003.04.23 | 7890 |
91 | Develop | [c] 신기한 atoi함수(www.game79.net) | hooni | 2003.04.23 | 7286 |
90 | Develop | [c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java) | hooni | 2003.04.23 | 7026 |
89 | Develop | [js] 점점 커지는 새창.. | hooni | 2003.04.23 | 7019 |
88 | Develop | [c] OpenGL 마우스 이벤트 | hooni | 2003.04.23 | 8751 |
87 | Develop | [js] 사라지는 브라우저 | hooni | 2003.04.23 | 6876 |
86 | Develop | [js] 이벤트 핸들러(Event Handlers) | hooni | 2003.04.23 | 6747 |