后退按钮显示空白屏幕

时间:2015-08-06 18:44:33

标签: android facebook webview

当我按下手机的“后退”按钮时,它会显示一个空白页面。当我再次按下“后退”按钮时,它会显示应用程序的主页面。我想在第一次回复时进入mainActivity页面。

mainActivity代码:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.text.style.SuperscriptSpan;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

Button b1,b2,b3,b4,b5,b6,b7;
EditText e1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b1=(Button)findViewById(R.id.call1);
    e1=(EditText)findViewById(R.id.call);

    b1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            String no=e1.getText().toString();
            Intent call=new Intent(Intent.ACTION_CALL);
            call.setData(Uri.parse("tel:"+no));
            startActivity(call);

            }
    });

    b2=(Button)findViewById(R.id.sens_sms);
    b2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent sendsms=new   
Intent(getApplicationContext(),waytosms.class);
            startActivity(sendsms);
        }
    });
    b3=(Button)findViewById(R.id.facebook);
    b3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent facebook=new Intent(MainActivity.this,facebook.class);
            startActivity(facebook);
            finish();

            }
    });
    b4=(Button)findViewById(R.id.gmail);
    b4.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent facebook=new Intent(MainActivity.this,gmail.class);
            startActivity(facebook);

        }
    });
    b5=(Button)findViewById(R.id.utube);
    b5.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent facebook=new Intent(MainActivity.this,utube.class);
            startActivity(facebook);

        }
    });
    b6=(Button)findViewById(R.id.google);
    b6.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent facebook=new Intent(MainActivity.this,google.class);
            startActivity(facebook);

        }
    });
    b7=(Button)findViewById(R.id.twitter);
    b7.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent facebook=new Intent(MainActivity.this,twitter.class);
            startActivity(facebook);

        }
    });
 }



}

这是我在这里用webview打开Facebook页面的Facebook课程:

public class facebook extends Activity{
WebView facebook;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook);

    facebook=(WebView)findViewById(R.id.webfacebook);
    facebook.getSettings().setJavaScriptEnabled(true);
    facebook.loadUrl("https://facebook.com");
}

此处我已实施onbackPressed()并致电finished() onbackpressed方法根本不会影响这一点。

@SuppressLint("NewApi")
 @Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    finish();
    Intent i=new Intent(facebook.this,MainActivity.class);
    startActivity(i);

}
}
  

1>首先是有社交网站的图标的主要活动页面   我点击Facebook图标它将打开facebook作为第二个facebookActivity页面,3>当我点击它时,它将打开一个空白页面并且4>。当我再次按下后退按钮时,它将打开主要活动页面...

1 个答案:

答案 0 :(得分:0)

像这样更改onBackPressed()方法:

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    finish();
    Intent i=new Intent(getApplicationContext(),MainActivity.class);
    startActivity(i);
}