Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1159 댓글 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 | Etc | [link] 유용한 사이트 링크. | hooni | 2013.08.19 | 71459 |
392 | Develop | [ios] 앱에서 다른 앱 실행시키기 | hooni | 2013.09.05 | 18536 |
391 | Develop | [ios] None IB vs. StoryBoard 샘플 소스 | hooni | 2013.09.06 | 16933 |
390 | Develop | [python] 애니팡, 캔디팡 매크로 | hooni | 2013.09.06 | 17322 |
389 | Develop | [ios] Hybrid 앱 스터디 발표 자료 | hooni | 2013.09.06 | 13713 |
388 | Etc | 영어. 외우면 도움되는 필수영어회화 표현 | hooni | 2013.09.09 | 20950 |
387 | Develop | [ios] 간단한 방법으로 OS버전 확인하기. | hooni | 2013.09.24 | 13312 |
386 | System/OS | [mac] SVN 1.8 업데이트 방법 | hooni | 2013.09.24 | 14569 |
385 | Etc | [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. | hooni | 2013.09.25 | 37497 |
384 | Develop | [ios] UIView에서 상위 UIViewController 가져오기 | hooni | 2013.09.27 | 20159 |
383 | Develop | [ios] GCD 변수 사용 예제 | hooni | 2013.10.01 | 12114 |
382 | System/OS | [linux] 우분투 APM + phpmyadmin 설치 | hooni | 2013.10.07 | 49325 |