Android发短信的代码为什么要放在子线程里,不然就会无响应? 5
我这个发短信的代码,为什么如果不放在子线程里就会卡,无响应?protectedvoidonCreate(BundlesavedInstanceState){System....
我这个发短信的代码,为什么如果不放在子线程里就会卡,无响应?
protected void onCreate(Bundle savedInstanceState) {
System.out.println("初始界面");
super.onCreate(savedInstanceState);
//去掉app的标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
new Thread(
new Runnable() {
@Override
public void run() {
int i=0;
while(true){
//循环发短信
SystemClock.sleep(5000);
i++;
System.out.println("发送一次短息"+i);
SmsManager smsManager=SmsManager.getDefault();
smsManager.sendTextMessage("10010", null, "hello", null, null);
}
}
}
).start();
} 展开
protected void onCreate(Bundle savedInstanceState) {
System.out.println("初始界面");
super.onCreate(savedInstanceState);
//去掉app的标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
new Thread(
new Runnable() {
@Override
public void run() {
int i=0;
while(true){
//循环发短信
SystemClock.sleep(5000);
i++;
System.out.println("发送一次短息"+i);
SmsManager smsManager=SmsManager.getDefault();
smsManager.sendTextMessage("10010", null, "hello", null, null);
}
}
}
).start();
} 展开
1个回答
展开全部
代码线程运行界面假死响应
Imports System.Threading
Public Class Form1
Delegate Sub qq163()
Dim cf As Thread
Dim bf As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cf = New Thread(AddressOf bc)
cf.Start()
End Sub
Sub bc()
Dim cs As New qq163(AddressOf js)
Invoke(cs)
End Sub
Sub js()
For i = 0 To 30
RichTextBox1.Text = RichTextBox1.Text & i & ","
RichTextBox1.Refresh()
Thread.CurrentThread.Sleep(1500)
Next
End SubEnd Class
何解决界面假死响应问题呢谢谢各位
Imports System.Threading
Public Class Form1
Delegate Sub qq163()
Dim cf As Thread
Dim bf As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cf = New Thread(AddressOf bc)
cf.Start()
End Sub
Sub bc()
Dim cs As New qq163(AddressOf js)
Invoke(cs)
End Sub
Sub js()
For i = 0 To 30
RichTextBox1.Text = RichTextBox1.Text & i & ","
RichTextBox1.Refresh()
Thread.CurrentThread.Sleep(1500)
Next
End SubEnd Class
何解决界面假死响应问题呢谢谢各位
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询