0
첫째, 내가이 문제와 관련된 모든 대답을 읽었지만이 오류를 해결하지 못했습니다. 내 프로그램이 실행되고 있지만 매우 느리고 느립니다. tryed 작은 이미지를 사용하여 비동기 작업을 사용하지만 내 문제가 계속됩니다. 여기 내 재활용 클래스 내 코드응용 프로그램이 주 스레드에서 너무 많은 작업을하고있을 수 있습니다. (안드로이드 스튜디오 에뮬레이터 및 실제 전화 에뮬레이터)
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
NotificationManager manager;
public Veri veri,veri1;
int x= 0;
private Timer autoUpdate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
veri1 = new Veri();
x=veri1.getList().size();
recyclerView= (RecyclerView) findViewById(R.id.my_recycler_view);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
onResume();
new AsyncCaller().execute();
}
@Override
protected void onStart() {
super.onStart();
}
////////////////////////////////////////////
private class AsyncCaller extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
autoUpdate = new Timer();
autoUpdate.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
updateHTML();
}
});
}
}, 0, 60000);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
////////////////////////////////////
private void updateHTML(){
// your logic here
RecyclerAdapter adapter=new RecyclerAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
veri = new Veri();
int a = veri.getList().size();
if(a!=x){
generateNotification(MainActivity.this,"Listede Degisim Var");
}
x=a;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
// search action
case R.id.action_location_found:
// location found
LocationFound();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void LocationFound() {
Intent i = new Intent(MainActivity.this, LocationFound.class);
startActivity(i);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
private void generateNotification(Context context,String message){
int notificationId = 001;
Intent viewIntent = new Intent(context, MainActivity.class);
PendingIntent viewPendingIntent =
PendingIntent.getActivity(context, 0, viewIntent, 0);
NotificationCompat.Builder notificationBuilder =
(NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.dikat)
.setContentTitle("Bildirim")
.setContentText(message)
.setContentIntent(viewPendingIntent)
.setAutoCancel(true)
.setSound(Uri.parse("android.resource://"
+ context.getPackageName() + "/" + R.raw.bildirim))
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, notificationBuilder.build());
}
} 여기
가 내 데이터 클래스public class Veri extends ActionBarActivity {
NotificationManager manager;
Notification myNotication;
String ip, db, un, passwords;
Connection connect,conn;
PreparedStatement stmt;
ResultSet rs;
TextView tv;
int position1=0;
Button b1;
ArrayList<String> data = new ArrayList<String>();
ArrayList<String> data2 = new ArrayList<String>();
public Veri(){
ip = "x.x.x.x";
un = "x";
passwords = "x";
db = "xxx";
connect = CONN(un, passwords, db, ip);
String query = "SELECT Adsoyad,(DATEPART(hour, BeklemeSuresi) * 3600) + (DATEPART(minute, BeklemeSuresi) * 60) + DATEPART(second, BeklemeSuresi) as SecondsFromMidnight,Durum FROM [dbo].[IslemiDevamEdenHasta] (1)";
try {
// connect = CONN(un, passwords, db, ip);
stmt = connect.prepareStatement(query);
rs = stmt.executeQuery();
while (rs.next()) {
int b = (int)rs.getInt("SecondsFromMidnight")/60;
if(b>50) {
String id = rs.getString("Adsoyad");
String id2 = rs.getString("Durum");
String full = id + " " + id2;
String a = "" + b;
data.add(full);
data2.add(a);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public ArrayList<String> getList() {
return data;
}
public ArrayList<String> getList2() {
return data2;
}
@SuppressLint("NewApi")
private Connection CONN(String _user, String _pass, String _DB,
String _server) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnURL = "jdbc:jtds:sqlserver://" + _server + ";"
+ "databaseName=" + _DB + ";user=" + _user + ";password="
+ _pass + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
} 여기
하고있다
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {
public Veri veri = new Veri();
int sayi=0;
ArrayList<String> liste = veri.getList();
ArrayList<String> liste2 = veri.getList2();
static ArrayList<String> liste3 = new ArrayList<String>() ;
Context context;
LayoutInflater inflater;
public RecyclerAdapter(Context context) {
this.context=context;
inflater=LayoutInflater.from(context);
}
@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v=inflater.inflate(R.layout.item_list, parent, false);
RecyclerViewHolder viewHolder=new RecyclerViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
liste3.add("a");
sayi = 0;
for (int j = 0; j < liste3.size(); j++) {
if (liste3.get(j).equals(liste.get(position))) {
sayi++;
}
if (sayi == 0) {
holder.tv1.setText(liste.get(position));
holder.tv2.setText(liste2.get(position));
holder.imageView.setOnClickListener(clickListener);
holder.imageView.setTag(holder);
} else {
holder.tv1.setText(liste.get(position));
holder.tv2.setText(liste2.get(position));
holder.imageView.setOnClickListener(clickListener);
holder.imageView.setImageResource(R.drawable.ic_checkin);
}
}
}
View.OnClickListener clickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerViewHolder vholder = (RecyclerViewHolder) v.getTag();
int position = vholder.getPosition();
//Toast.makeText(context,"This is position "+position,Toast.LENGTH_LONG).show();
vholder.imageView.setImageResource(R.drawable.ic_checkin);
liste3.add(liste.get(position));
}
};
@Override
public int getItemCount() {
return liste.size();
}
}
내 문제는 무엇입니까 ??
매번 recyclerView를 업데이트하고 계십니까? –
그냥 LIst
가능한 [해당 응용 프로그램이 주 스레드에서 너무 많은 작업을 수행하고있을 수 있습니다] (http://stackoverflow.com/questions/14678593/the-application-may-be) -doing-too-much-work-on-its-main-thread) – Ironman