Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1153 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
745 | Develop | [js] 자바스크립트(Javascript) 코드를 동적으로 삽입하는 방법.. | hooni | 2013.04.23 | 22875 |
744 | Develop | [ios] UILabel top alignㅎㅎ | hooni | 2013.04.23 | 22840 |
743 | Develop | 밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ | hooni | 2013.04.23 | 22816 |
742 | Develop | [vb] 문자열에서 태그 제거함수 (Visual Basic) | hooni | 2013.04.23 | 22621 |
741 | Develop | [iphone] 화면 전환 Portrait & Landscape Mode | hooni | 2013.04.23 | 22308 |
740 | Develop | [doc] Json Framework 설치와 사용 | hooni | 2013.04.23 | 21916 |
739 | Develop | [c] 재미있는 코딩.. | hooni | 2003.04.23 | 21316 |
738 | Develop | 프로그래밍에서 foo, bar 함수의 유래 | hooni | 2013.06.25 | 21247 |
737 | Develop | [c] 포인터 학습용 예제 소스 코드 | hooni | 2013.04.23 | 21029 |
736 | Develop | [c] 이진트리/트리 순회법 코드(전위/중위/후위) 5 | hooni | 2015.07.02 | 20918 |
735 | Develop | git 브런치 배우기 (링크) | hooni | 2013.07.09 | 20571 |
734 | Develop | [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 | hooni | 2013.04.23 | 20569 |