홈>
원격 서버에서 데이터를 가져오고 SQLite에서 데이터베이스를 만들고 공유 환경 설정을 업데이트하려고합니다. 이론적으로 UI (main) 스레드 이외의 별도 스레드에서 실행 해야하는 AsyncTask에 앞에서 언급 한 모든 작업을 배치했습니다. 또한 에뮬레이터가 아닌 실제 Android 장치에서 응용 프로그램을 실행하고 있습니다.
로그에 다음 정보가 표시됩니다.
I/Choreographer: Skipped 229 frames! The application may be doing too much work on its main thread.
소스 코드:
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.ExecutionException;
public class MainActivity extends AppCompatActivity {
TextView errorMessage;
Button retryAgainButton;
SharedPreferences sharedPrefs;
@SuppressLint("StaticFieldLeak")
public class FirstRunDBCreator extends AsyncTask<Void, Void, String> {
String result = "";
private Exception e = null;
@Override
protected void onPreExecute() {
sharedPrefs = getApplicationContext().getSharedPreferences("android.content.SharedPreference", Context.MODE_PRIVATE);
if(!sharedPrefs.contains("firstRun")) {
sharedPrefs.edit().putBoolean("firstRun", true).apply();
}
}
@Override
protected String doInBackground(Void... voids) {
String result = "";
// All the heavy operations here
// Fetching the data from the server here and creating/ storing data in my SQLite database
// I have also used transactions and SQLite preparedStatement to increase the insert speed
return result;
}
@SuppressLint("SetTextI18n")
@Override
protected void onPostExecute(String s) {
// Closing the database connections and handling any exceptions here
// Updating the UI elements such as diplaying the complete message or the visibility of a textview
}
}
public void initializeTheUIComponents() {
errorMessage = findViewById(R.id.errorMessage);
retryAgainButton = findViewById(R.id.retryAgainButton);
retryAgainButton.setClickable(false);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeTheUIComponents();
// Running the jumpToNextActivity after the screen and the UI elements have been rendered
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
try {
new FirstRunDBCreator().execute().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
});
}
}
비록 두 개의 TextViews를 제외하고 고해상도 이미지 나 무거운 프론트 엔드 구성 요소가 없으며 모든 무거운 처리가 백그라운드 스레드에서 수행되고 있다는 사실에 의해 안무가가 프레임을 건너 뛰게하는 이유는 무엇입니까? 내가 AsyncTask를 호출하기 때문입니까?
onCreate()
메소드 또는 코드에 코드가 있기 때문에
onPreExecute()
또는
onPostExecute()?
그것은
Runnable run()
아니면 그 문제에 대한 다른 이유가 있습니까?
- 답변 # 1
관련 자료
- flutter - Android에서 앱을 제거/재설치 한 후 SQFlite 데이터를 유지하는 가장 좋은 방법은 무엇입니까?
- azure devops - xamarinforms를 업데이트 한 후 Android에 대한 빌드 실패
- flutter - Android 앱의 경우 v 109 이후에 나오는 버전 코드
- 빌드 후 Cordova Android 앱 강제 종료
- java - Android 스튜디오, 앱을 다시 연 후 Fileproperties가 삭제됨
- Dart 및 Kotlin 플러그인을 비활성화 한 후 Android 스튜디오가 실행되지 않음
- Android searchview는 검색 후 recyclerview에서 숨겨집니다
- Android 41로 업데이트 한 후 Android Studio 오류
- java - Android에서 클릭 이벤트 후에도 이전 텍스트 표시
.get () 메소드를 호출하면이 경우 UI 스레드 인 현재 스레드에서 작동하므로없이 실행하십시오.
get
.