帧跳过 - 如何在android studio中创建第二个线程?

时间:2015-10-12 18:36:02

标签: android

我对android studio中的线程有疑问。 我的onCreate方法中有很多代码,包含大量的点击列表和文本管理器。 现在我有这个“80帧跳过”错误(在模拟器中)

好吧我知道80帧不是那么多,但我想避免让更多的帧跳过...我读到解决方案是一个新的线程,但不知何故,当我在oncreate中创建一个新的线程,我把我的代码放在其中我得到“300帧跳过”?!我认为我做的一切都正确我用新线程新的runnable我的线程我当然开始它...我做错了什么?可以有人请说我如何正确地制作一个线程以及放置它的位置? 谢谢!  好的伙伴在这里是我的代码(声明不包括定义)onCreate我只是制作一些东西,如拨打电话和发送短信..这些editexts是按钮的名称,用户可以编辑他想要的和所有这些东西保存在共享首选项..我得到了第二个保存数据的活动buti认为它现在没关系...我想把这个代码放在第二个线程中,不会跳过任何帧或至少没有多少...谢谢!

call.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("nummer", null).isEmpty() && sharedPreferences.getString("nummer", null) != null) {
                    phoneCall(sharedPreferences.getString("nummer", null));
                } else {
                    toasttext("Keine Nummer gefunden!");
                }
            }
        }
);


scharf.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("Scharfnummer", "").isEmpty() && sharedPreferences.getString("Scharfnummer", null) != null) {
                    sendSms(sharedPreferences.getString("Scharfnummer", null), sharedPreferences.getString("Scharftext", null));
                    toasttext("Erfolgreich gesendet!");
                } else {
                    toasttext("Keine Daten gefunden!");
                }
            }
        }
);

unscharf.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("Unscharfnummer", "").isEmpty() && sharedPreferences.getString("Unscharfnummer", null) != null) {
                    sendSms(sharedPreferences.getString("Unscharfnummer", null), sharedPreferences.getString("Unscharftext", null));
                    toasttext("Erfolgreich gesendet!");
                } else {
                    toasttext("Keine Daten gefunden!");
                }
            }
        }
);

cam1.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("cam1", "").isEmpty() && (sharedPreferences.getString("cam1", null) != null)) {
                    openLink(sharedPreferences.getString("cam1", null));
                } else {
                    toasttext("Kein Link gefunden!");
                }
            }
        }
);

cam2.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("cam2", "").isEmpty() && sharedPreferences.getString("cam2", null) != null) {
                    openLink(sharedPreferences.getString("cam2", null));
                } else {
                    toasttext("Kein Link gefunden!");
                }
            }
        }
);

cam3.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrate(78);
                if (!sharedPreferences.getString("cam3", "").isEmpty() && sharedPreferences.getString("cam3", null) != null) {
                    openLink(sharedPreferences.getString("cam3", null));
                } else {
                    toasttext("Kein Link gefunden!");
                }
            }
        }
);


editCall.setText(getData("editCall", "Call"));

editCall.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editCall", s.toString());
            }
        }
);

editArm.setText(getData("editArm", "Arm"));
editArm.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editArm", s.toString());
            }
        }
);
editDisarm.setText(getData("editDisarm", "Disarm"));
editDisarm.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editDisarm", s.toString());
            }
        }
);

editCam1.setText(getData("editCam1", "Cam1"));
editCam1.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editCam1", s.toString());
            }
        }
);

editCam2.setText(getData("editCam2", "Cam2"));
editCam2.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editCam2", s.toString());
            }
        }
);

editCam3.setText(getData("editCam3", "Cam1"));
editCam3.addTextChangedListener(
        new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                setData("editCam3", s.toString());
            }
        }
);

0 个答案:

没有答案