Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1172 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1053 | Develop | [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 | hooni | 2003.04.23 | 12530 |
1052 | Develop | [jsp][php] 간단한 강좌 자료.. | hooni | 2003.04.23 | 8114 |
1051 | Develop | [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 | hooni | 2003.04.23 | 7776 |
1050 | Develop | [c] 근의 공식으로 2차방정식 풀기.. | hooni | 2003.04.23 | 7778 |
1049 | Develop | [c] 이진트리(binary tree)의 운행.. | hooni | 2003.04.23 | 8271 |
1048 | Develop | [c] 이진트리(binary tree)의 특성 | hooni | 2003.04.23 | 9611 |
1047 | Develop | [자료구조] 트리(tree) 용어정리 | hooni | 2003.04.23 | 11072 |
1046 | Develop | [c] 농구팀 점수 산출 프로그램 소스 | hooni | 2003.04.23 | 7386 |
1045 | Develop | [c] 단어 입력/수정 프로그램 소스 | hooni | 2003.04.23 | 7029 |
1044 | Develop | [c] 정사각배열의 서브 배열의 최대 값 구하기 | hooni | 2003.04.23 | 7025 |
1043 | Develop | [c] 이진트리(binary tree) 샘플소스 (삽입, 삭제, 운행) | hooni | 2003.04.23 | 7810 |
1042 | Develop | [java] 컴포넌트 배치 ㅡ.,ㅡ; | hooni | 2003.04.23 | 7158 |