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

View file

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