【发布时间】:2014-12-06 11:53:07
【问题描述】:
在我的应用程序服务中,我正在获取服务器以获取新消息。
找到新消息后,我的服务应用程序必须打开屏幕并启动活动才能显示新消息。
在服务中我从服务器解析数据没有问题,但是当屏幕关闭导致睡眠服务和启动活动后,屏幕无法打开。
活动由服务启动:
public void onCreate (Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
requestWindowFeature ( Window.FEATURE_NO_TITLE );
getWindow ().setFlags ( WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );
PowerManager powermanager = ((PowerManager)getBaseContext ().getSystemService( Context.POWER_SERVICE));
wakeLock=powermanager.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "TsmsScreenOn");
wakeLock.acquire ( 10000 );
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 1.0f;
getWindow().setAttributes(params);
setContentView ( R.layout.service_view_dialog );
}
我的总结服务:
public class ToobaPayamakService extends Service {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
}
private Runnable sendUpdatesToUI = new Runnable() {
};
private void DisplayLoggingInfo() {
}
public int callRequestFromServer(){
if (G.checkInternetConnection ()) {
try {
Cursor c = db.getCursorFirstItemReceived ( username );
c.moveToFirst ();
if (c.moveToFirst ()) {
receive_lastID = c.getString ( c.getColumnIndex ( "lastId" ) );
}
c.close ();
unread = checkWebService ( Integer.valueOf ( receive_lastID ) );
} catch (Exception e) {
e.printStackTrace ();
}
Log.e ( "unread: ", unread + "" );
if (unread != 0) {
G.config_username = username;
G.config_password = password;
try {
G.getRequestFromServerByService ( Long.parseLong ( receive_lastID ), unread, contentResolver );
result_count = unread;
} catch (JSONException e) {
e.printStackTrace ();
}
}
}
return result_count;
}
/* ----------------------------------------------------------------------------------------------------------------- notifyTest */
public void notifyTest ( int unread ) {
Intent i = new Intent ();
i.setClass ( this, ServiceDialog.class );
i.putExtra ( "username", username );
i.putExtra ( "password", password );
i.putExtra ( "unread" , counter );
i.putExtra ( "notify" , notify );
i.setFlags ( Intent.FLAG_ACTIVITY_REORDER_TO_FRONT );
i.setFlags ( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity ( i );
}
}
【问题讨论】:
-
请检查我编辑的答案以获取更多详细信息:)