Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1147 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
793 | Develop | [lego] 세그웨이 이것만 볼것.. ㅎㅎ | hooni | 2013.04.23 | 33534 |
792 | Develop | [c] C로 구현한 CGI - 방명록 | hooni | 2003.04.23 | 33427 |
791 | Develop | [js] jQuery 코드 작성시 편리한 HTML 템플릿 | hooni | 2013.12.17 | 33067 |
790 | Develop | [c++] 웹폼(webform)전송과 http 파일 업로드 샘플 | hooni | 2013.04.23 | 33059 |
789 | Develop | 베지어 곡선(Bézier curve) 알고리즘(spline 곡선) 3 | hooni | 2013.04.23 | 32841 |
788 | Develop | [ios] 디렉토리 하하하.. | hooni | 2013.04.23 | 32628 |
787 | Develop | [js] 키보드 아스키코드(ASCII) 코드보기 | hooni | 2003.04.23 | 32476 |
786 | Develop | [c] C로 구현한 CGI - 달력과 날짜계산기 | hooni | 2003.04.23 | 32269 |
785 | Develop | [ios] 개발 기초 가이드 링크.. | hooni | 2013.04.23 | 31364 |
784 | Develop | [js] jQuery 관련 문서 ㅎㅎ | hooni | 2013.04.23 | 31219 |
783 | Develop | [android] 디바이스(시뮬레이터) hosts 파일 수정하기 | hooni | 2013.04.23 | 31064 |
782 | Develop | 서기의 PHP 동영상 강의(싱싱해) | hooni | 2013.05.15 | 30977 |