I/Choreographer:跳过了8帧!应用程序可能在其主线程上做了太多的工作



我的应用程序没有从数据库中获取数据。它显示了一个空白文本视图,并显示了下面给出的logcat上的错误。。。。请帮帮我。我已经到了工作的最后期限了。。。。。

2020-02-26 11:53:30.062 29392-29392/com.example.d.specs I/TextToSpeech:成功绑定到com.google.android.tts2020-02-26 11:53:30.070 29392-29418/com.example.d.specs d/ColorExSystemServiceHelper:checkColorExSystemService className=com.google.android.tts.service.GoogleTTSService2020-02-26 11:53:30.75 29392-29392/com.example.d.specs d/WindowManager:添加到mViews:DecorView@fa8568c[SecondOneActivity],this=android.view.WindowManagerGlobal@b0c7f51,pkg=com.example.d.specs2020-02-26 11:53:30.083 29392-29392/com.example.d.specs I/TextToSpeech:连接到ComponentInfo{com.google.android.tts/com.google.andrio.tts.service.GoogleTTSService}2020-02-26 11:53:30.91 29392-29497/com.example.d.specs I/TextToSpeech:设置到ComponentInfo的连接{com.google.android.tts.com/google.andrio.tts.service.GoogleTTSService}2020-02-26 11:53:30.264 29392-29392/com.example.d.specs I/Choreographer:跳过了8帧!应用程序可能在其主线程上做了太多的工作。2020-02-26 11:53:30.553 29392-29392/com.example.d.specs d/SurfaceView:238649477 updateRequestedVisibility,mViewVisibility:true,mWindowVisibility:false,mWindowStopped:false by android.view.SurfaceView.onWindowVisibilityChanged:292 android.vew.view.dispatchWindowVisibilicyChanged:13970 android.vview.ViewGroup.dispatchWindowsVisibilitychanged:1580 android.view.ViewGroup.DispatchWindowvisilityChanged:1580 android.view.WiewGroup.ddispatchWindowVisiilityChangeD:1580android.view.ViewGroup.dispatchWindowVisibilityChanged:1580 android.vview.ViewGroup.dedispatchWindowVisiilityChanged:15802020-02-26 11:53:30.553 29392-29392/com.example.d.specs I/SurfaceView:238649477更改:创建=假格式=假大小=假可见=真左=假顶部=假2020-02-26 11:53:30.553 29392-29392/com.example.d.specs I/SurfaceView:238649477 Cur surface:surface(name=null(/@0xfeb1e8,visible=false2020-02-26 11:53:30.555 29392-29392/com.example.d.specs I/SurfaceView:238649477 visibleChanged:true->SurfaceHolder。回调.surfaceDestroyed2020-02-26 11:53:30.557 29392-29392/com.example.d.specs V/SurfaceView:布局:x=0 y=264 w=1094 h=1944,frame=Rect(0,10941944(2020-02-26 11:53:30.559 29392-29480/com.example.d.specs d/SurfaceView:135700481 windowPositionLost,frameNr=02020-02-26 11:53:30.576 29392-29392/com.example.d.specs d/SurfaceView:238649477 updateRequestedVisibility,mViewVisibility:true,mWindowVisibility:false,mWindowStopped:true by android.view.SurfaceView.windowStopped:264 android.vview.ViewRootImpl.setWindowStopped:1722 android.vindowManagerGlobal.setStopedState:685 android.app.Activity.performStop:8206 android.app/ActivityThread.callActivityOnStop:4899 android.ap.ActivityThread performStopActivityInner:4877 android.app.ActivityThread.handleStopActivity:4959android.app.servertransaction.StopActivityItem.execute:412020-02-26 11:54:08.979 29392-29392/com.example.d.specs I/Choreographer:跳过了2帧!应用程序可能在其主线程上做了太多的工作。


import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.core.view.GestureDetectorCompat;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import java.util.ArrayList;
import java.util.Locale;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
public class SecondOneActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
private static final String TAG = "SampleActivity";
private GestureDetectorCompat GestureDetect;
private TextToSpeech tts;
TextToSpeech txt;
//array declaration
ArrayList<String> array1;
ArrayList<String> array2;
//global variable
String glo;
String nameget;
String priceget;
TextView text;
FirebaseAuth firebaseAuth;
FirebaseUser firebaseUser;
DatabaseReference databasefetch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_one);
Bundle bundle = getIntent().getExtras(); //get the intent and data  passed
//next check that bundle is not null
if (bundle != null) {
String scanResult = bundle.getString("SCAN_RESULT");
//try loging out the value
Log.i("value", scanResult);
glo = scanResult;
}
//typeCast
long l = Long.parseLong(glo);
//initialize arraylists
array1 = new ArrayList<String>();
array2 = new ArrayList<String>();
txt=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status!=TextToSpeech.ERROR)
{
txt.setLanguage(Locale.UK);
}
}
});
GestureDetect = new GestureDetectorCompat(this,this);
GestureDetect.setOnDoubleTapListener(this);
text = (TextView) findViewById(R.id.textView3);
//database initialize
firebaseAuth = FirebaseAuth.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();

//database data fetching : from here onwards
//database query as "select * from save where id=l;
databasefetch = FirebaseDatabase.getInstance().getReference().child("DPOS");
Query query = databasefetch.orderByChild("id").equalTo(l);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Log.i("TAG", "sujith annan");
String name = snapshot.child("name").getValue().toString();
String details = snapshot.child("details").getValue().toString();
String price = snapshot.child("price").getValue().toString();
// nameget = name;
// priceget = price;
text = (TextView) findViewById(R.id.textView3);
//to print
text.setText("nProduct Name : " + name + "nDetails : " + details + "nPrice : " + price);
//text to speech
String toSpeak = text.getText().toString();
Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
txt.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
throw databaseError.toException(); // never ignore errors
}
});

}

@Override
public boolean onTouchEvent(MotionEvent event) {
GestureDetect.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
//text to speech
String toSpeak = text.getText().toString();
Toast.makeText(getApplicationContext(),toSpeak,Toast.LENGTH_SHORT).show();
txt.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
Intent intent=new Intent(SecondOneActivity.this,SecondActivity.class);
startActivity(intent);
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Toast.makeText(this,"Item saved for billing",Toast.LENGTH_SHORT).show();
array1.add(nameget);
array2.add(priceget);
return false;
}
@Override
public void onBackPressed() {
Intent in =new Intent(this,BillingActivity.class);
in.putStringArrayListExtra("arr1",array1);
in.putStringArrayListExtra("arr2",array2);
startActivity(in);
super.onBackPressed();
}

}

您在主线程上做的任务太多了。因为android应用程序运行一个管理GUI的线程。在您的代码中,您在主线程上调用"Firebase"。这就是为什么它会错过一些要在屏幕上渲染的帧。

如果许多帧未命中,则有时您的"UI"会被冻结。避免调用web服务或主线程上的DB操作。

为了避免这种情况,您可以使用"AsyncTask"或"服务"来执行此任务。

感谢

最新更新