Contents

Views 1296 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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


?

List of Articles
No. Category Subject Author Date Views
84 Develop [ios] 아이폰용 앱 오픈 소스들 hooni 2013.04.23 468331
83 Develop [ios] 언어, 지역, 국가 설정 가져오기 hooni 2014.05.12 270696
82 Develop [android] 만화 어플 소스코드 file hooni 2013.04.23 92909
81 Algorithm 디피헬만(Diffie-Hellman) 초간단 개념.. hooni 2013.04.23 81072
80 Develop [c#] Hashtable <-> Json (dll 포함) file hooni 2013.04.23 80714
79 Develop [C#] MD5, SHA1 해시 & 인코딩 hooni 2013.04.23 77941
78 Develop [android] 점심 해결 앱 소스 코드 ㅋㅋ file hooni 2013.04.23 76466
77 PPT [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 file hooni 2013.04.23 75703
76 Develop [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드) file hooni 2013.04.23 72023
75 Develop [ios] Random Thoughts: Rand() vs. arc4random() hooni 2013.10.31 68108
74 Develop [vb] 비주얼 베이직 자격증용 ㅎㅎ hooni 2003.04.23 61527
73 Develop [android] Canvas를 이용해 이미지 확대/축소 하기 hooni 2013.04.23 60786
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7