Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1295 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
393 | Develop |
[c] 프로그램 코드(c/c++)를 html 파일로 변환
![]() |
hooni | 2013.04.23 | 7685 |
392 | Develop |
[c] 전위 표기법으로 연산 예제..
![]() |
hooni | 2013.04.23 | 9311 |
391 | PPT |
[doc] 정보보호학술대회 논문지 ㅋㅋ
![]() |
hooni | 2013.04.23 | 12190 |
390 | Develop | [ajax] 샘플 코드와 한글처리에 대한 간단한 설명 | hooni | 2013.04.23 | 6867 |
389 | Etc | GSM에서 음성이 실리는 과정 요약.. | hooni | 2013.04.23 | 17576 |
388 | Develop | [js] 폼(form) 전송시 중복 클릭 방지 간단한 구문 | hooni | 2013.04.23 | 9324 |
387 | Develop | [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 | hooni | 2013.04.23 | 6354 |
386 | Database | [sql] 간단한 통계 서브쿼리 예제.. | hooni | 2013.04.23 | 15147 |
385 | Develop | [java] Sieve of Eratosthenes (에라토스테네스의 체) | hooni | 2013.04.23 | 9345 |
384 | Develop |
[c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수
![]() |
hooni | 2013.04.23 | 8082 |
383 | Develop |
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6909 |
382 | Develop |
[php] 무조건 다운로드 받도록 header 세팅
![]() |
hooni | 2013.04.23 | 7411 |