Develop
2016.11.15 10:23
[android] Calling activity function from separate class
조회 수 1165 댓글 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 •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1029 | Develop | [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 | hooni | 2021.01.29 | 1392 |
1028 | Develop | [swift] NotificationCenter 간단 예제 | hooni | 2021.01.27 | 8125 |
1027 | System/OS | [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories) | hooni | 2015.01.02 | 1551 |
1026 | Etc | [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. | hooni | 2013.09.25 | 37506 |
1025 | System/OS | [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback) | hooni | 2014.11.27 | 1568 |
1024 | System/OS | [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우 | hooni | 2014.12.18 | 995 |
1023 | Database | [sql] 한눈에 보이는 Join | hooni | 2014.02.19 | 8470 |
1022 | Database | [sql] 쿼리로 문자열 검색해서 일괄 치환하기 | hooni | 2014.02.13 | 9976 |
1021 | System/OS | [sql] 중복데이터 삭제 쿼리 | hooni | 2013.04.23 | 14739 |
1020 | System/OS | [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct) 1 | hooni | 2013.04.23 | 33946 |
1019 | System/OS | [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문) | hooni | 2003.04.23 | 12845 |
1018 | Database | [sql] 간단한 통계 서브쿼리 예제.. | hooni | 2013.04.23 | 15091 |