在您的项目中实现 Runnable。运行此代码
while (cursor.moveToNext())
{
String address = cursor.getString(1);
String body = cursor.getString(3);
// Loading too long
System.out.println("======> Mobile number => "+address);
System.out.println("=====> SMS Text => "+body);
sms.add("Address=> "+address+"\n SMS => "+body);
}
//return sms;// Make a global variable which can hold values here...
handler.sendEmptyMessage(0);
在
run()
方法。现在像这样启动线程:
Thread fetchSmsThread = new Thread(this);
progressDialog = ProgressDialog.show(context,title,message);
fetchSmsThread.start();
处理程序代码:
Handler handler = new Handler()
{
//////Catch Message Here.. and Dismiss dialog...
///Note You have to declare progress dialog as global so that you can access it here...
}
有关 runnable 的进一步帮助,请执行以下操作:
如何在 Android 中运行 Runnable 线程?
如果您不想使用 Runnable,请使用 Android AsynClass,请遵循:
AsyncTask Android 示例