Don't call blocking functions from ui thread.

This commit is contained in:
Felix Ableitner 2014-07-23 00:36:27 +02:00
parent 387202d92d
commit 3ffecaa310
2 changed files with 30 additions and 10 deletions

View file

@ -42,8 +42,13 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCertificateManager.deleteCertificate(cert); new Thread(new Runnable() {
mMovedCertificatesStorage.delete(cert); @Override
public void run() {
mCertificateManager.deleteCertificate(cert);
mMovedCertificatesStorage.delete(cert);
}
}).start();
} }
}); });
colorRes = R.color.background_system_certificate; colorRes = R.color.background_system_certificate;
@ -53,8 +58,13 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mCertificateManager.moveCertificateToSystem(cert); new Thread(new Runnable() {
mMovedCertificatesStorage.insert(cert); @Override
public void run() {
mCertificateManager.moveCertificateToSystem(cert);
mMovedCertificatesStorage.insert(cert);
}
}).start();
} }
}); });
colorRes = R.color.background_user_certificate; colorRes = R.color.background_user_certificate;

View file

@ -31,8 +31,13 @@ public class MainActivity extends ListActivity {
mCertificateAdapter = mCertificateAdapter =
new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage); new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage);
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false)); new Thread(new Runnable() {
mCertificateAdapter.addAll(mMovedCertificatesStorage.list()); @Override
public void run() {
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false));
mCertificateAdapter.addAll(mMovedCertificatesStorage.list());
}
}).start();
mListView.setAdapter(mCertificateAdapter); mListView.setAdapter(mCertificateAdapter);
} }
@ -50,10 +55,15 @@ public class MainActivity extends ListActivity {
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
for (Certificate c : list) { new Thread(new Runnable() {
c = mCertificateManager.moveCertificateToSystem(c); @Override
mMovedCertificatesStorage.insert(c); public void run() {
} for (Certificate c : list) {
c = mCertificateManager.moveCertificateToSystem(c);
mMovedCertificatesStorage.insert(c);
}
}
}).start();
} }
}) })
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)