Develop
2016.11.15 10:23
[android] Calling activity function from separate class
Views 1303 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 •
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
84 | Develop | [ios] 아이폰용 앱 오픈 소스들 | hooni | 2013.04.23 | 468515 |
83 | Develop | [ios] 언어, 지역, 국가 설정 가져오기 | hooni | 2014.05.12 | 270874 |
82 | Develop |
[android] 만화 어플 소스코드
![]() |
hooni | 2013.04.23 | 92912 |
81 | Algorithm | 디피헬만(Diffie-Hellman) 초간단 개념.. | hooni | 2013.04.23 | 81076 |
80 | Develop |
[c#] Hashtable <-> Json (dll 포함)
![]() |
hooni | 2013.04.23 | 80717 |
79 | Develop | [C#] MD5, SHA1 해시 & 인코딩 | hooni | 2013.04.23 | 77949 |
78 | Develop |
[android] 점심 해결 앱 소스 코드 ㅋㅋ
![]() |
hooni | 2013.04.23 | 76472 |
77 | PPT |
[android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료
![]() |
hooni | 2013.04.23 | 75705 |
76 | Develop |
[json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드)
![]() |
hooni | 2013.04.23 | 72025 |
75 | Develop | [ios] Random Thoughts: Rand() vs. arc4random() | hooni | 2013.10.31 | 68113 |
74 | Develop | [vb] 비주얼 베이직 자격증용 ㅎㅎ | hooni | 2003.04.23 | 61541 |
73 | Develop | [android] Canvas를 이용해 이미지 확대/축소 하기 | hooni | 2013.04.23 | 60789 |