Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1155 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
817 | Develop | [Xcode] 디버깅 옵션 | hooni | 2013.04.23 | 57196 |
816 | Develop | [vb] 비주얼 베이직 205페이지 | hooni | 2003.04.23 | 56037 |
815 | Develop | [vb] 비쥬얼 베이직 기출 문제 연습 | hooni | 2003.04.23 | 55134 |
814 | Develop | [vb] 비주얼 베이직 173페이지 | hooni | 2003.04.23 | 54802 |
813 | Develop | [vb] 비쥬얼 베이직 기출 문제 연습2 | hooni | 2003.04.23 | 54338 |
812 | Develop | [iphone] view에 대한 조사 ㅡ,.ㅡ; | hooni | 2013.04.23 | 54071 |
811 | Develop | [vb] 비쥬얼 베이직으로.. | hooni | 2003.04.23 | 52997 |
810 | Develop | [android] GCM 사용하기 1 (GCM 서비스 신청하기) | hooni | 2013.07.06 | 51355 |
809 | Develop | [android]개발 가이드 및 한글화 문서 | hooni | 2013.04.23 | 47514 |
808 | Develop | [android] ArrayAdapter를 이용하여 출력하기 | hooni | 2013.04.23 | 47337 |
807 | Develop | [ios] UIAlertView 초간단 샘플 ㅎㅎ | hooni | 2013.10.14 | 46106 |
806 | Develop | [ios] 배열(NSArray) 연산과 간단한 애니메이션(split images) | hooni | 2013.10.31 | 45438 |