[android] Calling activity function from separate class
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
-
[link] 유용한 사이트 링크.
-
[ios] 앱에서 다른 앱 실행시키기
-
[ios] None IB vs. StoryBoard 샘플 소스
-
[python] 애니팡, 캔디팡 매크로
-
[ios] Hybrid 앱 스터디 발표 자료
-
영어. 외우면 도움되는 필수영어회화 표현
-
[ios] 간단한 방법으로 OS버전 확인하기.
-
[mac] SVN 1.8 업데이트 방법
-
[svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때..
-
[ios] UIView에서 상위 UIViewController 가져오기
-
[ios] GCD 변수 사용 예제
-
[linux] 우분투 APM + phpmyadmin 설치