Develop
2016.11.15 10:23
[android] Calling activity function from separate class
Views 7412 Comment 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 •
-
캘리포니아 운전면허 문제
-
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
-
[ios] 카테고리 확장 메소드를 찾지 못하는 경우
-
개인적으로 쓰고 있는 zshrc 파일
-
[ios] GMT Date와 Local Date 변환하기
-
RSVP 란?
-
[펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들
-
[mac] VirtualBox 실행 스크립트와 bash_profile 설정
-
[ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기
-
Ubuntu Desktop RDP Setup - 24.04 LTS
-
[c#] 툴바 소스.. 개인적으로 만드는거..
-
[ubuntu] 우분투 18.04에 PHP5 설치하기