--- android.app.Dialog.class异常 ------- sendDismissMessage();
活动bizlead.carlife.Transmission已泄露窗口 com.android.internal.policy.impl.PhoneWindow $ {DecorView 42407878 最初添加的V.E ..... R ...... D 0,0-1026,288} android.view.WindowLeaked:活动bizlead.carlife.Transmission有 泄露的窗户 com.android.internal.policy.impl.PhoneWindow $ {DecorView 42407878 最初添加的V.E ..... R ...... D 0,0-1026,288} android.view.ViewRootImpl。(ViewRootImpl.java:355)at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216) 在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) 在android.app.Dialog.show(Dialog.java:289)at bizlead.carlife.HttpPostTask.onPreExecute(HttpPostTask.java:85)at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)at android.os.AsyncTask.execute(AsyncTask.java:534)at bizlead.carlife.Transmission.exec_post(Transmission.java:402)at bizlead.carlife.Transmission.access $ 4(Transmission.java:373)at bizlead.carlife.Transmission $ 2.onClick(Transmission.java:317)at com.android.internal.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:166) 在android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:213)at android.app.ActivityThread.main(ActivityThread.java:5092)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:797) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564)at dalvik.system.NativeStart.main(本机方法) org.apache.http.client.HttpResponseException:内部服务器错误 org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71) 在 org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59) 在 org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657) 在 org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627) 在 org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616) 在 bizlead.carlife.UploadAsyncTask.doInBackground(UploadAsyncTask.java:57) 在 bizlead.carlife.UploadAsyncTask.doInBackground(UploadAsyncTask.java:1) 在android.os.AsyncTask $ 2.call(AsyncTask.java:287)at java.util.concurrent.FutureTask.run(FutureTask.java:234)at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)at at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:573) 在java.lang.Thread.run(Thread.java:856)
@SuppressWarnings( {"deprecation", "unused"} )
public class Transmission extends Activity implements OnClickListener, OnItemSelectedListener {
private final static int BT_COUNT=5, TV_COUNT=6, HYAKU=100, TARGET_WIDTH=300, TARGET_HEIGHT=300;
private int saveCount, callCount, orderCount;
private final static int BT_ID[]=
{ R.id.bt_trans1,
R.id.bt_trans2,
R.id.bt_trans3,
R.id.bt_trans4,
R.id.bt_trans6
};
private final static int TV_ID[]=
{
R.id.tv_trans1,
R.id.tv_trans2,
R.id.tv_trans3,
R.id.tv_trans4,
R.id.tv_trans5,
R.id.tv_trans6
};
private final static String BT_NAME[]=
{
"場所変更",
"個人情報変更",
"車両情報変更",
"カメラ起動",
"決定して送信する"
};
private final static String TV_NAME[]=
{
"注文日時",
"お問い合わせID",
"タクシーを呼ぶ場所",
"個人情報を確認",
"車両情報を確認",
"事故写真を撮る"
};
private String tabCount[], CAR_KEY_DATA[], PER_KEY_DATA[], times="", local_file="", regId="", cameraPath="";
private SharedPreferences sp;
private Editor editor;
private ImageView iv_camera;
private Button bt_trans[]=new Button[BT_COUNT];
private TextView tv_trans[]=new TextView[TV_COUNT];
private TextView tv_order_select;
private TextView orderDate, orderId, addressData;
private ListView lv_per, lv_car;
private Spinner spinner, sp_order_select;
private Uri mSaveUri, pictureUri;
private Bitmap picture;
private boolean imageupsita=false;
ArrayAdapter<String>adapter;
ArrayAdapter<String>order_adapter;
AsyncTask<Void, Void, Void>asyncTask=null;
UploadAsyncTask uptask;
private PersonOpenHelper hlpr=null;
private SQLiteDatabase db=null;
private Cursor c=null;
private String orders="";
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String strDirPath=Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/";
Log.v("strDirPath=", strDirPath+"です");
checkNotNull(SERVER_URL, SERVER_URL);
checkNotNull(SENDER_ID, SENDER_ID);
GCMRegistrar.checkDevice(getApplicationContext());
GCMRegistrar.checkManifest(getApplicationContext());
setContentView(R.layout.activity_transmission);
getPushId();
sp=PreferenceManager.getDefaultSharedPreferences(this);
editor=sp.edit();
spinner=(Spinner)findViewById(R.id.sp_trans11);
spinner.setOnItemSelectedListener(this);
tabCount=new String[sp.getInt("tabCount", 2)-1];
sp_order_select=(Spinner)findViewById(R.id.sp_order_select);
sp_order_select.setOnItemSelectedListener(this);
order_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, ORDER_SELECT);
sp_order_select.setAdapter(order_adapter);
sp_order_select.setBackgroundColor(Color.CYAN);
for(int i=0; i<tabCount.length; i++)
tabCount[i]=(i+1)+"台目の自動車で呼ぶ";
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, tabCount);
spinner.setAdapter(adapter);
spinner.setBackgroundColor(Color.CYAN);
PER_KEY_DATA=new String[PER_KEY.length];
CAR_KEY_DATA=new String[CAR_KEY.length];
for(int i=0; i<PER_KEY_DATA.length; i++)
PER_KEY_DATA[i]=sp.getString(PER_KEY[i], "");
for(int i=0; i<CAR_KEY_DATA.length; i++)
CAR_KEY_DATA[i]=sp.getString(CAR_KEY[i], "");
lv_per=(ListView)findViewById(R.id.lv_per);
lv_per=EastSys.List2gyou(PER_KEY, PER_KEY_DATA, lv_per, this);
lv_per=EastSys.ListScroll(lv_per);
lv_car=(ListView)findViewById(R.id.lv_car);
orderDate=(TextView)findViewById(R.id.order_date);
orderDate.setText(timeData().toString());
orderId=(TextView)findViewById(R.id.order_id);
orderId.setText(""+(int)((Math.random()*100)));
addressData=(TextView)findViewById(R.id.address1);
addressData.setText(sp.getString("getAddress", "住所が選択されていません").toString());
for(int i=0; i<BT_COUNT; i++)
{
bt_trans[i]=(Button)findViewById(BT_ID[i]);
bt_trans[i].setOnClickListener(this);
bt_trans[i].setText(BT_NAME[i]);
bt_trans[i].setBackgroundResource(R.drawable.home_reca);
bt_trans[i].setTextColor(Color.WHITE);
bt_trans[i].setTextSize(13);
bt_trans[i].setWidth(400);
}
bt_trans[BT_COUNT-1].setBackgroundResource(R.drawable.home_setting);
for(int i=0; i<TV_COUNT; i++)
{
tv_trans[i]=(TextView)findViewById(TV_ID[i]);
tv_trans[i].setText(TV_NAME[i]);
tv_trans[i].setTextSize(16);
tv_trans[i].setTypeface(Typeface.DEFAULT_BOLD);
}
tv_order_select=(TextView)findViewById(R.id.tv_order_select);
tv_order_select.setTextSize(16);
tv_order_select.setTypeface(Typeface.DEFAULT_BOLD);
iv_camera=(ImageView)findViewById(R.id.iv_camera);
}
@Override
public void onClick(View v)
{
if(v==bt_trans[0]) //地図確認
finish();
if(v==bt_trans[1]) //個人情報変更
startActivityForResult(new Intent(Transmission.this, Personal.class), 0);
if(v==bt_trans[2]) //車両情報変更
startActivityForResult(new Intent(Transmission.this, Car.class), 0);
if(v==bt_trans[3]) //カメラ起動
{
imageupsita=false;
ContentValues values=new ContentValues();
values.put(MediaStore.Images.Media.TITLE, System.currentTimeMillis()+".jpg");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
pictureUri=getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
cameraPath = getPathUri(this, pictureUri);
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
startActivityForResult(intent, HYAKU);
imageupsita = true;
}
if(v==bt_trans[4]) { //決定送信
new AlertDialog.Builder(this)
.setTitle("最終確認")
.setMessage(order())
.setPositiveButton("呼ぶ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
editor.putBoolean("呼び出し中", true);
editor.commit();
if( imageupsita ) {
uptask = new UploadAsyncTask( Transmission.this );
uptask.context = Transmission.this;
String filePath = getPathUri(getApplicationContext(), pictureUri);
uptask.execute(filePath);
imageupsita = false;
}
//smsPush();
exec_post();
SaveDatabase();
startActivity(new Intent(Transmission.this, Home.class));
finish();
();
c.close();
db.close();
}
}).setNegativeButton("確認し直す", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
return;
}
})
.create()
.show();
}
}
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
if( requestCode == HYAKU && resultCode == Activity.RESULT_OK )
iv_camera.setImageBitmap( ( Bitmap )data.getExtras().get( "data" ) );
}
protected String timeData()
{
Time time=new Time("Asia/Tokyo");
time.setToNow();
times=time.year+"年 "+(time.month+1)+"月 "+time.monthDay+"日 "+time.hour+"時 "+time.minute+"分 ";
return times;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
for(int i=0; i<CAR_KEY.length; i++)
CAR_KEY_DATA[i]=sp.getString(CAR_KEY[i]+"_"+arg2, "");
lv_car=EastSys.List2gyou(CAR_KEY, CAR_KEY_DATA, lv_car, this);
lv_car=EastSys.ListScroll(lv_car);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
private void exec_post() {
String urls=SERVER_URL+DIR_NAME+FILE_NAME;
HttpPostTask task=new HttpPostTask(this, urls,
new HttpPostHandler(){
@Override
public void onPostCompleted(String response){
//Toast.makeText(getApplicationContext(), "完了!", Toast.LENGTH_SHORT).show();
Log.v("response="+response, "aaa");
}
@Override
public void onPostFailed(String response){
//Toast.makeText(getApplicationContext(), "失敗!"+response, Toast.LENGTH_SHORT).show();
}
}
);
for(int i=0; i<PER_KEY.length; i++)
task.addPostParam(PER_KEY[i], PER_KEY_DATA[i]);
for(int i=0; i<CAR_KEY.length; i++)
task.addPostParam(CAR_KEY[i], CAR_KEY_DATA[i]);
task.addPostParam("REG_ID", regId);
task.addPostParam("orderId", orderId.getText().toString());
task.execute();
}
private void getPushId(){
registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
final String regId = GCMRegistrar.getRegistrationId(getApplicationContext());
Log.v("regId="+regId, "あああ");
if( regId.equals("") ) {
GCMRegistrar.register(Transmission.this, SENDER_ID);
} else {
final Context context = this;
asyncTask = new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... params){
boolean registred = ServerUtilities.register(context, regId);
if (!registred) GCMRegistrar.unregister(context);
return null;
}
@Override
protected void onPostExecute( Void result ){
asyncTask = null;
}
};
asyncTask.execute(null, null, null);
}
}
@Override
protected void onDestroy(){
if(asyncTask!=null) asyncTask.cancel(true);
unregisterReceiver(mHandleMessageReceiver);
GCMRegistrar.onDestroy(this);
super.onDestroy();
}
private void checkNotNull(Object reference, String name){
if(reference==null){
throw new NullPointerException(getString(R.string.error_config, name));
}
}
public static String getPathUri(Context context, Uri uri) {
ContentResolver contentResolver = context.getContentResolver();
String[] columns = { MediaStore.Images.Media.DATA };
Cursor cursor = contentResolver.query(uri, columns, null, null, null);
cursor.moveToFirst();
String path = cursor.getString(0);
cursor.close();
return path;
}
private void SaveDatabase(){
hlpr = new PersonOpenHelper(this);
db = hlpr.getWritableDatabase();
c = db.rawQuery("SELECT * FROM "+PERSON_TB, null);
ContentValues val = new ContentValues();
for(int i=0; i<PER_KEY.length; i++)
val.put(PER_KEY_DB[i], PER_KEY_DATA[i]);
for(int i=0; i<CAR_KEY.length; i++)
val.put(CAR_KEY_DB[i], CAR_KEY_DATA[i]);
val.put(HISTORY_TITLE[0], addressData.getText().toString());
val.put(HISTORY_TITLE[1], timeData());
val.put("CAMERA_PATH", cameraPath);
val.put("ORDER_SELECT", sp_order_select.getSelectedItem().toString());
Log.v("sp_order_select = ", "です" + sp_order_select.getSelectedItem().toString());
db.insert(PERSON_TB, null, val);
Log.v("CCC1", "111");
c.close();
Log.v("BBB1", "111");
db.close();
}
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent){
}
};
private String order(){
String setOrderTitle="";
String address = addressData.getText().toString();
String select = sp_order_select.getSelectedItem().toString();
switch (sp_order_select.getSelectedItemPosition()) {
case 0: // 事故が起きた
setOrderTitle = address+"にタクシーを手配します、よろしいですか?";
break;
case 1: // B/J
setOrderTitle = address + "にB/Jをします、よろしいですか?";
break;
default :
setOrderTitle = address + "に" + select + "します、よろしくお願い致します。";
}
return setOrderTitle;
}
答案 0 :(得分:0)
在致电dialog.show()
之前,您必须执行以下检查:
if(!isFinishing){
new AlertDialog.Builder(this)
.setTitle("最終確認")
.setMessage(order())
.setPositiveButton("呼ぶ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
editor.putBoolean("呼び出し中", true);
editor.commit();
if( imageupsita ) {
uptask = new UploadAsyncTask( Transmission.this );
uptask.context = Transmission.this;
String filePath = getPathUri(getApplicationContext(), pictureUri);
uptask.execute(filePath);
imageupsita = false;
}
//smsPush();
exec_post();
SaveDatabase();
startActivity(new Intent(Transmission.this, Home.class));
finish();
();
c.close();
db.close();
}
}).setNegativeButton("確認し直す", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
return;
}
})
.create()
.show();
}
您必须检查,因为您无法将对话框附加到未处于正常状态的活动。