0

webview から Android アクティビティ ページに戻る方法については、次のリンクを使用します。

ソリューションは、トーストメッセージのみを表示するのに最適です..

しかし、ここで直面している問題は、トースト メッセージの後に新しいアクティビティを開始しようとしたときに、VM の中止エラー メッセージが表示されることです。

public class JavaScriptInterface{
    Context mContext;

    /** Instantiate the interface and set the context */
    JavaScriptInterface(Context c) {
        mContext = c;
    }

    /** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        menuScreenActivity  menu=new menuScreenActivity ();
        menu.logout();//here i try to call the logut method
    }
}

menuScreenActivityアクティビティで、ログアウトというメソッドを作成しました

menuScreenActivity のメソッド

public void logout(){
      Intent myIntent= new Intent(menuScreenActivity.this,LoginActivity.class);
      startActivity(myIntent);
    }

私の丸太の猫は言う

 JNI WARNING: jarray 0x405a2478 points to non-array object (Ljava/lang/String;)
 "WebViewCoreThread" prio=5 tid=9 NATIVE
  | group="main" sCount=0 dsCount=0 obj=0x4058d718 self=0x1fecb0
  | sysTid=746 nice=0 sched=0/0 cgrp=default handle=5148120
   | schedstat=( 23519331303 11309830622 1216 )
at android.webkit.WebViewCore.nativeTouchUp(Native Method)
at android.webkit.WebViewCore.nativeTouchUp(Native Method)
at android.webkit.WebViewCore.access$3300(WebViewCore.java:53)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
at java.lang.Thread.run(Thread.java:1019)
VM aborting

この問題を解決する方法を教えてください。

4

3 に答える 3

0

menuScreenActivity menu=new menuScreenActivity ();ほぼ確実に間違っています。Activityandを使用して作成しないでくださいnewContextを に渡すためだけにそれを行っていたようですIntent。既にContext参照を保存しているため、それを使用してインテントを起動できます (Activity コンテキストを渡した場合)。

/** Show a toast from the web page */
    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        Intent myIntent= new Intent(mContext,LoginActivity.class);
        mContext.startActivity(myIntent);
    }  
于 2013-01-15T08:20:22.160 に答える
0

menuScreenActivityでログアウト方法を静的に変更できます。

public static logout(Context context){
  Intent myIntent= new Intent(context,LoginActivity.class);
  context.startActivity(myIntent);
}

そして、JavaScriptInterface で静的メソッドを呼び出します。

menuScreenActivity.startActivity(mContext);
于 2013-01-15T08:29:48.027 に答える
0

Intentメソッドで作成したlogout()ものをインテントと呼び、myIntent を起動しようとするのは正常ですIntentか?

于 2013-01-15T07:42:43.687 に答える