应用程序仅停止在S6上工作

时间:2016-09-25 05:46:03

标签: android android-studio

我不知道这里发生了什么。我的应用程序在J5和J6上完美运行,但它停止在S6(所有手机上的相同Android版本)上工作

只有在我有以下代码时它才会停止:
当我发布时,android studio会说0错误和0警告

我对android studio来说还是一个新手,我已经尝试使用Thread myThread而没有线程

public class IntroPage extends AppCompatActivity {

private ImageButton btnSkip;
private ImageButton btnUpdate;

// need this for post
RequestQueue requestQueue;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // full screen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.intro_page);


    requestQueue = Volley.newRequestQueue(getApplicationContext());

    // outlets
    btnSkip = (ImageButton) findViewById(R.id.btnSkip);
    btnUpdate = (ImageButton) findViewById(R.id.btnUpdate);

    // hide both on default
    btnSkip.setVisibility(View.VISIBLE);
    btnUpdate.setVisibility(View.GONE);


    // when submit is clicked
    btnSkip.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent startMainScreen = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(startMainScreen);
            finish();
        }
    });

    // update
    btnUpdate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=ddddddddd"));
            startActivity(intent);
        }
    });


    // get app version
    PackageInfo pInfo = null;
    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    String version = pInfo.versionName;
    final Integer versionCode = pInfo.versionCode;


    // conn
    Thread myThread = new Thread() {
        @Override
        public void run() {
            StringRequest jsonObjectRequest = new StringRequest(Request.Method.POST,
                    "https://www.domain.com/appVersion.php", new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject responseJson = new JSONObject(response);
                        Log.i("JSON RESPONSE", responseJson.toString());

                        // check if we are up to date
                        if (responseJson.getInt("version") > versionCode) {
                            btnSkip.setVisibility(View.GONE);
                            btnUpdate.setVisibility(View.VISIBLE);
                        } else {
                            btnSkip.setVisibility(View.VISIBLE);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }) {
                // This whole section can be deleted if we dont post vars
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> parameters = new HashMap<>();
                    parameters.put("club", "Murmur");
                    parameters.put("device", "Android");

                    return parameters;
                }
            };
            jsonObjectRequest.setShouldCache(false);
            // requestQueue.getCache().remove("https://www.domain.com/appVersion.php");
            requestQueue.add(jsonObjectRequest);
        }
    };
    myThread.start();
}
}

0 个答案:

没有答案