我的应用程序有一个服务:PushMessageService,接收到广播消息
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />就启动服务,代码如下:
public class MyAppReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
intent = new Intent(context, PushMessageService.class);
context.startService(intent);
}
}
PushMessageService.java代码如下:
package com.wanzhao.service.message;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.wanzhao.R;
import com.wanzhao.data.ApplicationData;
import com.wanzhao.ui.LoginActivity;
import com.wanzhao.ui.MessagePushActivity;
import com.wanzhao.util.HttpUtils;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.IBinder;
import android.os.Binder;
import android.os.Message;
import static com.wanzhao.data.ApplicationData.ISLOGIN;
public class PushMessageService extends Service {
private static final String TAG = "LocalService";
private IBinder binder = new PushMessageService.LocalBinder();
private HttpUtils httpUtil;
public static String SESSION_ID = "";
@Override
public IBinder onBind(Intent intent) {
return binder;
}
private void showMessageNotification(String messageTitle,
String messageContent) {
// 消息通知栏
// 定义通知栏展现的内容信息
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "万朝消息通知";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// 定义下拉通知栏时要展现的内容信息
Context context = getApplicationContext();
Intent notificationIntent;
if(ISLOGIN){
notificationIntent = new Intent(this, MessagePushActivity.class);
}else{
notificationIntent = new Intent(this, LoginActivity.class);
}
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, messageTitle, messageContent,
contentIntent);
((ApplicationData) getApplication()).mNotificationManager.notify(1,
notification);
}
@Override
public void onCreate() {
super.onCreate();
Handler handle = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
JSONObject jsonObj = (JSONObject) msg.obj;
if (null != jsonObj) {
try {
if (!"".equals(jsonObj.getString("type"))
&& !"".equals(jsonObj.getString("info"))) {
showMessageNotification(jsonObj.getString("type"),
jsonObj.getString("info"));
}
this.obtainMessage();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
return;
}
}
};
SharedPreferences sp = PushMessageService.this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
String userName = sp.getString("userName", "null");
String password = sp.getString("password", "null");
if(!"null".equals(userName) && !"null".equals(password)){
List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
paramsList.add(new BasicNameValuePair("userName", userName));
paramsList.add(new BasicNameValuePair("password", password));
MyHttpThread httpThread = new MyHttpThread(handle, paramsList);
httpThread.start();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
public class MyHttpThread extends Thread {
private Handler handler;
private List<NameValuePair> paramsList;
public MyHttpThread(Handler h, List<NameValuePair> params) {
this.handler = h;
this.paramsList = params;
httpUtil = new HttpUtils();
}
@Override
public void run() {
final Message msg = new Message();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
JSONObject jsonObj = httpUtil.httpRequest(paramsList,
"?con=infoPush&ac=sendPushMessage&r="
+ new Random().nextInt());
msg.obj = jsonObj;
handler.sendMessage(msg);
}
}, 0, 10000);
}
}
// 定义内容类继承Binder
public class LocalBinder extends Binder {
// 返回本地服务
PushMessageService getService() {
return PushMessageService.this;
}
}
}
这个是应用程序启动的Activity:IndexActivity.java
public class IndexActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.index_activity);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(IndexActivity.this, LoginActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2000);
}
@Override
protected void onPause(){
super.onPause();
this.finish();
}
@Override
protected void onStop(){
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
这是登陆的界面:LoginActivity.java
问题就出在这里,在这个界面停留个几秒不操作就会出现应用程序无响应,如果进入这个界面就输入用户名的话,等输入了用户名再输入密码的时候,也出现无响应
public class LoginActivity extends Activity {
private Button loginBtn;
private EditText userName_edt;
private EditText password_edt;
private TextView title_txt;
private Handler handler;
private Dialog waitDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userName_edt = (EditText)findViewById(R.id.userName_edit);
password_edt = (EditText)findViewById(R.id.password_edit);
title_txt = (TextView) findViewById(R.id.title_txt);
title_txt.setText(R.string.wanzhao_sys_name);
loginBtn = (Button) findViewById(R.id.login_btn);
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String userName = userName_edt.getText().toString().trim();
final String password = password_edt.getText().toString().trim();
if("".equals(userName)){
Toast.makeText(getApplicationContext(), "请输入用户名", Toast.LENGTH_LONG).show();
return;
}
if("".equals(password)){
Toast.makeText(getApplicationContext(), "请输入密码", Toast.LENGTH_LONG).show();
return;
}
handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
waitDialog.dismiss();
if(null != msg.obj){
JSONObject jsonObj = (JSONObject) msg.obj;
try {
if(!(0 == jsonObj.getInt("isLogin"))){
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_LONG).show();
}else{
USERROLE = jsonObj.getInt("role") + "";
ISREGISTER = jsonObj.getInt("isRegister") + "";
USERNAME = userName;
ISLOGIN = true;
SharedPreferences sp = LoginActivity.this.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString("userName", USERNAME);
editor.putString("password", new AppUtils().getMd5Str(password));
editor.commit();
Intent intent1=new Intent(LoginActivity.this,PushMessageService.class);
startService(intent1);
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}else{
Toast.makeText(getApplicationContext(), "请检查网络", Toast.LENGTH_LONG).show();
}
this.obtainMessage();
}
};
AppUserCtrl userCtrl = new AppUserCtrl(LoginActivity.this);
userCtrl.userLogin(LoginActivity.this,userName, password, handler);
waitDialog = new Dialog(LoginActivity.this, R.style.my_wait_dialog_view_style);
waitDialog.setContentView(R.layout.my_wait_dialog_view);
waitDialog.show();
}
});
}
@Override
protected void onPause(){
super.onPause();
this.finish();
}
@Override
protected void onStop(){
super.onStop();
}
@Override
protected void onDestroy(){
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
this.finish();
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
请各位帮帮忙吧,新手,对程序的设计实在是不在行,望不吝赐教,谢谢!
13 个解决方案
#1
大神们,帮我看看啊,为什么没人回复,哥自己顶一个先
#2
log贴出来看看
#3
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(IndexActivity.this, LoginActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2000);
为什么这样写?
你这样写的意思就是每隔2秒就启动一次activity
#4
log里没有报错信息
#5
这个不是每个2秒启动一次activity,而是2秒后启动activity,你百度一下timer.schedule(TimerTask,int)这个方法,你说的每隔2秒执行任务的是另外的一个重载的方法,有3个参数,第三个参数才是设置间隔时间的
#6
看到了,你是对的
#7
引用 2 楼 iltgcl 的回复:
log贴出来看看
log里没有报错信息
你程序都ANR了,怎么会没有log呢?
#8
看log吧 anr这么严重的问题 系统有log日志的 可以直接找 也可以重现
#9
引用 2 楼 iltgcl 的回复:
log贴出来看看
log里没有报错信息
你程序都ANR了,怎么会没有log呢?
刚刚又调试了一下,log是这样的
07-15 13:41:00.259: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:00.259: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=-896216834>>>
07-15 13:41:00.850: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:09.089: I/Adreno200-EGL(2305): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build: (Merge)
07-15 13:41:09.089: I/Adreno200-EGL(2305): Build Date: 11/27/12 Tue
07-15 13:41:09.089: I/Adreno200-EGL(2305): Local Branch:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Remote Branch:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Local Patches:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Reconstruct Branch:
07-15 13:41:10.250: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=-520824501>>>
07-15 13:41:13.033: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:20.250: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=650286566>>>
07-15 13:41:21.902: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:23.204: W/dalvikvm(2305): threadid=3: spin on suspend #1 threadid=1 (pcf=0)
07-15 13:41:23.954: W/dalvikvm(2305): threadid=3: spin on suspend #2 threadid=1 (pcf=0)
07-15 13:41:23.954: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:23.954: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:23.954: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:23.954: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:23.954: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:23.954: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:23.954: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:23.954: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:23.954: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1052 stm=8 core=1
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:23.954: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:23.954: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:23.954: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:23.954: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:23.954: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:23.954: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
07-15 13:41:24.705: W/dalvikvm(2305): threadid=3: spin on suspend #3 threadid=1 (pcf=0)
07-15 13:41:24.705: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:24.705: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:24.705: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:24.705: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:24.705: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:24.705: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:24.705: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:24.705: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:24.705: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1120 stm=8 core=0
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:24.705: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:24.705: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:24.705: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:24.705: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:24.705: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:24.705: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
07-15 13:41:25.456: W/dalvikvm(2305): threadid=3: spin on suspend #4 threadid=1 (pcf=0)
07-15 13:41:25.456: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:25.456: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:25.456: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:25.456: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:25.456: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:25.456: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:25.456: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:25.456: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:25.456: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1190 stm=8 core=0
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:25.456: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:25.456: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:25.456: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:25.456: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:25.456: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:25.456: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
帮忙看看是什么问题,谢谢了
#10
1 ANR之後,系统会将日志LOG写到到data\anr\traces.txt文件
2
AppUserCtrl是怎麼實現的,懷疑有問題。將這幾行註釋掉,用其他簡單的方法發送登錄信息,打log來檢查。
2
AppUserCtrl userCtrl = new AppUserCtrl(LoginActivity.this);
userCtrl.userLogin(LoginActivity.this,userName, password, handler);
waitDialog = new Dialog(LoginActivity.this, R.style.my_wait_dialog_view_style);
waitDialog.setContentView(R.layout.my_wait_dialog_view);
waitDialog.show();
AppUserCtrl是怎麼實現的,懷疑有問題。將這幾行註釋掉,用其他簡單的方法發送登錄信息,打log來檢查。
#11
我程序和你的一样的问题,如何解决的
#12
那个定时器不应该写在主线程中,在起个子线程进行操作
#13
ANR 错误 你把耗时的动作都放到线程里去 service 中主线程阻塞一样会 ANR的
#1
大神们,帮我看看啊,为什么没人回复,哥自己顶一个先
#2
log贴出来看看
#3
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(IndexActivity.this, LoginActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2000);
为什么这样写?
你这样写的意思就是每隔2秒就启动一次activity
#4
log贴出来看看
log里没有报错信息
#5
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(IndexActivity.this, LoginActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2000);
为什么这样写?
你这样写的意思就是每隔2秒就启动一次activity
这个不是每个2秒启动一次activity,而是2秒后启动activity,你百度一下timer.schedule(TimerTask,int)这个方法,你说的每隔2秒执行任务的是另外的一个重载的方法,有3个参数,第三个参数才是设置间隔时间的
#6
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(IndexActivity.this, LoginActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2000);
为什么这样写?
你这样写的意思就是每隔2秒就启动一次activity
这个不是每个2秒启动一次activity,而是2秒后启动activity,你百度一下timer.schedule(TimerTask,int)这个方法,你说的每隔2秒执行任务的是另外的一个重载的方法,有3个参数,第三个参数才是设置间隔时间的
看到了,你是对的
#7
引用 2 楼 iltgcl 的回复:
log贴出来看看
log里没有报错信息
你程序都ANR了,怎么会没有log呢?
#8
看log吧 anr这么严重的问题 系统有log日志的 可以直接找 也可以重现
#9
引用 2 楼 iltgcl 的回复:
log贴出来看看
log里没有报错信息
你程序都ANR了,怎么会没有log呢?
刚刚又调试了一下,log是这样的
07-15 13:41:00.259: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:00.259: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=-896216834>>>
07-15 13:41:00.850: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:09.089: I/Adreno200-EGL(2305): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build: (Merge)
07-15 13:41:09.089: I/Adreno200-EGL(2305): Build Date: 11/27/12 Tue
07-15 13:41:09.089: I/Adreno200-EGL(2305): Local Branch:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Remote Branch:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Local Patches:
07-15 13:41:09.089: I/Adreno200-EGL(2305): Reconstruct Branch:
07-15 13:41:10.250: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=-520824501>>>
07-15 13:41:13.033: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:20.250: D/urlStr(2305): <<<http://服务地址/android/index.php?con=infoPush&ac=sendPushMessage&r=650286566>>>
07-15 13:41:21.902: D/responseStr(2305): >>>{"resultCode":"4","resultMessage":"","type":"","info":"","finishtime":""}<<<
07-15 13:41:23.204: W/dalvikvm(2305): threadid=3: spin on suspend #1 threadid=1 (pcf=0)
07-15 13:41:23.954: W/dalvikvm(2305): threadid=3: spin on suspend #2 threadid=1 (pcf=0)
07-15 13:41:23.954: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:23.954: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:23.954: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:23.954: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:23.954: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:23.954: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:23.954: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:23.954: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:23.954: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1052 stm=8 core=1
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:23.954: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:23.954: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:23.954: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:23.954: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:23.954: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:23.954: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:23.954: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:23.954: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
07-15 13:41:24.705: W/dalvikvm(2305): threadid=3: spin on suspend #3 threadid=1 (pcf=0)
07-15 13:41:24.705: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:24.705: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:24.705: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:24.705: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:24.705: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:24.705: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:24.705: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:24.705: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:24.705: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1120 stm=8 core=0
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:24.705: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:24.705: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:24.705: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:24.705: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:24.705: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:24.705: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:24.705: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:24.705: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
07-15 13:41:25.456: W/dalvikvm(2305): threadid=3: spin on suspend #4 threadid=1 (pcf=0)
07-15 13:41:25.456: I/dalvikvm(2305): "Signal Catcher" daemon prio=5 tid=3 RUNNABLE
07-15 13:41:25.456: I/dalvikvm(2305): | group="system" sCount=0 dsCount=0 obj=0x41d74188 self=0x68faf010
07-15 13:41:25.456: I/dalvikvm(2305): | sysTid=2309 nice=0 sched=0/0 cgrp=apps handle=1734508448
07-15 13:41:25.456: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=0 stm=0 core=2
07-15 13:41:25.456: I/dalvikvm(2305): at dalvik.system.NativeStart.run(Native Method)
07-15 13:41:25.456: I/dalvikvm(2305): "main" prio=5 tid=1 RUNNABLE JIT
07-15 13:41:25.456: I/dalvikvm(2305): | group="main" sCount=1 dsCount=0 obj=0x4112f700 self=0x4006d010
07-15 13:41:25.456: I/dalvikvm(2305): | sysTid=2305 nice=0 sched=0/0 cgrp=apps handle=1074972208
07-15 13:41:25.456: I/dalvikvm(2305): | schedstat=( 0 0 0 ) utm=1190 stm=8 core=0
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:~262)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Looper.removeSyncBarrier(Looper.java:242)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:995)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4242)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer.doFrame(Choreographer.java:525)
07-15 13:41:25.456: I/dalvikvm(2305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Handler.handleCallback(Handler.java:615)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 13:41:25.456: I/dalvikvm(2305): at android.os.Looper.loop(Looper.java:137)
07-15 13:41:25.456: I/dalvikvm(2305): at android.app.ActivityThread.main(ActivityThread.java:4790)
07-15 13:41:25.456: I/dalvikvm(2305): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 13:41:25.456: I/dalvikvm(2305): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 13:41:25.456: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 13:41:25.456: I/dalvikvm(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 13:41:25.456: I/dalvikvm(2305): at dalvik.system.NativeStart.main(Native Method)
帮忙看看是什么问题,谢谢了
#10
1 ANR之後,系统会将日志LOG写到到data\anr\traces.txt文件
2
AppUserCtrl是怎麼實現的,懷疑有問題。將這幾行註釋掉,用其他簡單的方法發送登錄信息,打log來檢查。
2
AppUserCtrl userCtrl = new AppUserCtrl(LoginActivity.this);
userCtrl.userLogin(LoginActivity.this,userName, password, handler);
waitDialog = new Dialog(LoginActivity.this, R.style.my_wait_dialog_view_style);
waitDialog.setContentView(R.layout.my_wait_dialog_view);
waitDialog.show();
AppUserCtrl是怎麼實現的,懷疑有問題。將這幾行註釋掉,用其他簡單的方法發送登錄信息,打log來檢查。
#11
我程序和你的一样的问题,如何解决的
#12
那个定时器不应该写在主线程中,在起个子线程进行操作
#13
ANR 错误 你把耗时的动作都放到线程里去 service 中主线程阻塞一样会 ANR的