package com.example.test;import java.util.Timer;
import java.util.TimerTask;import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;public class MainActivity extends Activity {

Button btnPopupWindow;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 强制横屏 SCREEN_ORIENTATION_LANDSCAPE
// 强制竖屏 SCREEN_ORIENTATION_PORTRAIT
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//一旦设置横屏自动弹出就报错 setContentView(R.layout.activity_main); // 启动定时器
Timer timer = new Timer();
timer.schedule(new initPopupWindow(), 100);
}
// 用于Handler类ui线程与其他线程进行交互
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
showPopupWindow();
break;
}
}
};
// TimerTask类
private class initPopupWindow extends TimerTask {
public void run() {
Message message = new Message();
message.what = 1;
mHandler.sendMessage(message);
}
}

// 自动启动PopupWindow
public void showPopupWindow() {
showPopupWindow(MainActivity.this,
MainActivity.this.findViewById(R.id.Button01));
}

public void showPopupWindow(Context context, View parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View vPopupWindow = inflater.inflate(R.layout.popupwindow, null,
false);//popupwindow为弹出框样式
final PopupWindow pw = new PopupWindow(vPopupWindow, 500, 400, true); // 显示popupWindow对话框
pw.showAtLocation(parent, Gravity.CENTER, 0, 0);
}}-----------------------------------------------------------
一旦设置了强制横屏自动弹出就会报错 请问这是为什么 ?

解决方案 »

  1.   

    抱什么错误?还有log?运行时报错,还是编译错误?
      

  2.   

    05-09 07:14:27.045: E/EsSyncAdapterService(20938): Sync failure
    05-09 07:14:27.045: E/EsSyncAdapterService(20938): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.network.HttpTransaction.execute(HttpTransaction.java:312)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:219)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.api.TacoTruckOperation.start(TacoTruckOperation.java:327)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:185)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.api.TacoTruckOperation.start(TacoTruckOperation.java:318)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.network.HttpOperation.start(HttpOperation.java:177)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.content.EsPostsData.doActivityStreamSync(EsPostsData.java:251)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.content.EsPostsData.syncActivities(EsPostsData.java:167)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.service.EsSyncAdapterService.doFullSync(EsSyncAdapterService.java:614)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.service.EsSyncAdapterService.doSync(EsSyncAdapterService.java:566)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.service.EsSyncAdapterService.access$100(EsSyncAdapterService.java:52)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at com.google.android.apps.plus.service.EsSyncAdapterService$SyncAdapterImpl.onPerformSync(EsSyncAdapterService.java:408)
    05-09 07:14:27.045: E/EsSyncAdapterService(20938):  at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:247)
      

  3.   

    这个log和你发的代码啥关系?
      

  4.   

    你发的LOG和横竖屏报错没关系!
    你把setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);这句放到Handler里执行,也就是你的ACTIVITY跑起来之后再让他横竖屏。