1

次のコードを使用して、webview を表示しています。これを onCreate() で使用しました

import java.io.IOException;
import java.net.URL;
import java.util.Calendar;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;




import com.myrestaurant.utils.MyProgressDialog;


import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class BeapSoundActivity extends Activity implements OnClickListener{

    WebView wvLink;
    MyProgressDialog pgrDialog;
    AlertDialog alertDialog;
//  Button btnStop;
    static TextView pending_number;
     MediaPlayer mMediaPlayer;
     int pending;
     PendingIntent pendingIntent ;

     static {

//         StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

           StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().permitAll().build());
       }

     MyProgressDialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.beap_sound);
        pending_number=(TextView)findViewById(R.id.order_num);

           Log.e("tvvvv",""+BeapSoundActivity. pending_number);
//      btnStop=(Button)findViewById(R.id.stop);
        wvLink=(WebView)findViewById(R.id.webview1);
//      btnStop.setOnClickListener(this);





//       mMediaPlayer = new MediaPlayer();
           TelephonyManager manager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
            if(manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE){
//              return "Tablet";
            }else{
//              return "Mobile";
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            } 
//       doInBack dob=new doInBack();
//         

         Intent svc=new Intent(BeapSoundActivity.this, BackgroundService.class);
           pendingIntent = PendingIntent.getService(BeapSoundActivity.this, 0, svc, 0);

           AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

           Calendar calendar = Calendar.getInstance();
           calendar.setTimeInMillis(System.currentTimeMillis());
           calendar.add(Calendar.SECOND, 2);
           alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 10*1000, pendingIntent);







//          startService(svc);

           if(pgrDialog!=null){
            pgrDialog.dismiss();
        }
        pgrDialog=MyProgressDialog.show(BeapSoundActivity.this, null,null);
        alertDialog = new AlertDialog.Builder(this).create();

        wvLink.setWebViewClient(new myWebClient());
        wvLink.getSettings().setJavaScriptEnabled(true);
        wvLink.loadUrl(" http://mybusinessapp2.testshell.net");
//          pgrDialog.dismiss();
        Log.e("pend",""+pending);




    }



    public void setPendings(){

    }



//end of doBack 


    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);

        }

         public void onPageFinished(WebView view, String url) {
//                Log.i(TAG, "Finished loading URL: " +url);

                if (pgrDialog.isShowing()) {
                    pgrDialog.dismiss();
                }
            }

         public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//                Log.e(TAG, "Error: " + description);
                Toast.makeText(BeapSoundActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
                alertDialog.setTitle("Error");
                alertDialog.setMessage(description);
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alertDialog.show();
            }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            return true;

        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
//      if(v.equals(btnStop)){
//          mMediaPlayer.stop();
//      }
    }
}



  Here is Logcat output:



    03-25 15:18:30.984: E/WindowManager(4133): Activity com.myrestaurant.activities.BeapSoundActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41ded2d8 V.E..... R.....ID 0,0-60,60} that was originally added here
    03-25 15:18:30.984: E/WindowManager(4133): android.view.WindowLeaked: Activity com.myrestaurant.activities.BeapSoundActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41ded2d8 V.E..... R.....ID 0,0-60,60} that was originally added here
    03-25 15:18:30.984: E/WindowManager(4133):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.Dialog.show(Dialog.java:281)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.myrestaurant.utils.MyProgressDialog.show(MyProgressDialog.java:45)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.myrestaurant.utils.MyProgressDialog.show(MyProgressDialog.java:27)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.myrestaurant.utils.MyProgressDialog.show(MyProgressDialog.java:22)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.myrestaurant.activities.BeapSoundActivity.onCreate(BeapSoundActivity.java:96)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.Activity.performCreate(Activity.java:5104)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.os.Handler.dispatchMessage(Handler.java:99)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.os.Looper.loop(Looper.java:137)
    03-25 15:18:30.984: E/WindowManager(4133):  at android.app.ActivityThread.main(ActivityThread.java:5039)
    03-25 15:18:30.984: E/WindowManager(4133):  at java.lang.reflect.Method.invokeNative(Native Method)
    03-25 15:18:30.984: E/WindowManager(4133):  at java.lang.reflect.Method.invoke(Method.java:511)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    03-25 15:18:30.984: E/WindowManager(4133):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    03-25 15:18:30.984: E/WindowManager(4133):  at dalvik.system.NativeStart.main(Native Method)
    03-25 15:18:31.016: E/tvvvv(4133): android.widget.TextView{41d5be50 V.ED.... ......ID 0,0-0,0 #7f080006 app:id/order_num}

これを Google Nexus (7 インチ タブレット) で実行してもエラーは発生しませんが、Nexus フォンではエラーが発生します。この問題を解決するのを手伝ってくれる人はいますか?

4

0 に答える 0