我运行线程时MI设备显示此错误,而三星设备不显示

时间:2019-02-06 12:57:06

标签: android

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".second">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.857" />

    <ImageView
        android:id="@+id/imageReva"
        android:layout_width="179dp"
        android:layout_height="174dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/rev" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLargeInverse"
        android:layout_width="224dp"
        android:layout_height="86dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:indeterminate="false"
        android:max="100"
        android:minWidth="200dp"
        android:minHeight="50dp"
        android:progress="1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.926" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="LOCATE"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.709" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:ems="10"
        android:hint="Route number"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.529"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.498" />
</android.support.constraint.ConstraintLayout>`

是XML代码enter image description here。我正在尝试为大学跟踪系统构建应用程序。我正在运行一项服务,该服务在后台等待用户等待我使用进度条,问题是我给你错误的吗。我如何处理线程,这是问题,它可以在NXT(oreo)上的samsun银河上工作,但在几乎所有mi设备上都不能工作。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    progressBar = (ProgressBar)findViewById(R.id.progressBar);
    progressBar.setVisibility(View.INVISIBLE);
    tv = (TextView)findViewById(R.id.textView);
    ed = (EditText)findViewById(R.id.editText);
    tv.setVisibility(View.INVISIBLE);
    if ( !isNetworkAvailable() ) {

       net();
    }
    b = (Button)findViewById(R.id.button);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isNetworkAvailable()) {

                net();
            } else {
                con.route = ed.getText().toString().trim();
                if (con.route.isEmpty()) {
                    ed.setError("Please enter your route number!");
                    ed.requestFocus();
                } else {
                    int rout = Integer.parseInt(con.route);
                    con.integer_route = rout;
                /*
                replace the below line in if condition when all the routes are done
                rout>0 && rout <= 30*/
                    if (rout == 21) {
                        Intent i = new Intent(second.this, TestService.class);
                        second.this.startService(i);
                        count++;
                        somee();
                    } else {
                        Toast.makeText(getApplicationContext(), "please enter valid route number!", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        }
    });
}

private void net() {
    AlertDialog.Builder builder = new AlertDialog.Builder(
            second.this);
    builder.setCancelable(false);
    builder.setTitle("Alert !!!");
    builder.setMessage("There seems to be no active internet connection to your device \nplease connect to internet and try again");
    builder.setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                                    int which) {
                    finish();
                }
            });
    builder.show();
}

private void somee() {
    if (count ==1) {
        progressBar.setVisibility(View.VISIBLE);
        tv.setVisibility(View.VISIBLE);

        new Thread(new Runnable() {
            public void run() {
                while (progressStatus < 100) {
                    progressStatus += 1;
                    // Update the progress bar and display the
                    //current value in the text view
                    handler.post(new Runnable() {
                        public void run() {
                            progressBar.setProgress(progressStatus);
                            tv.setText(progressStatus + "/" + progressBar.getMax());
                        }
                    });
                    try {
                        // Sleep for 600 milliseconds.
                        Thread.sleep(600);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if ((!con.longitude.isEmpty()) || (!con.latitude.isEmpty())) {

                        count = 0;
                        progressStatus = 0;
                        shouldthisactivityrun = false;

                        startActivity(new Intent(second.this, error.class));


                        finish();
                        break;
                    }
                }
                progressBar.setVisibility(View.INVISIBLE);
                if (shouldthisactivityrun){
                    count = 0;
                    progressStatus=0;
                    startActivity(new Intent(second.this, error.class));}

            }
        }).start();
    }

0 个答案:

没有答案