2013-07-04 60 views
0

我正在開發幻燈片功能,此停止和重新啓動在幻燈片流中創建問題,我們可以更改它嗎?在SCREEN_OFF意圖調用時調用的活動(生命週期)的奇怪行爲

日誌的生命週期方法

07-04 22:47:27.944: D/ReceiverActivity(7365): Activity Life cycle - onStart called 
07-04 22:47:27.944: D/ReceiverActivity(7365): Activity Life cycle - onResume called 
07-04 22:47:28.467: D/ReceiverActivity(7365): Activity Life cycle - onStop called 
07-04 22:47:29.139: D/ReceiverActivity(7365): Activity Life cycle - onRestart called 
07-04 22:47:29.139: D/ReceiverActivity(7365): Activity Life cycle - onStart called 
07-04 22:47:29.139: D/ReceiverActivity(7365): Activity Life cycle - onResume called 

這裏是我的應用程序代碼片段提前

@Override 
public void onReceive(final Context context, final Intent intent) { 
    if(action.equals(Intent.ACTION_SCREEN_OFF)) { 
     Intent ri = new Intent(context, ReceiverActivity.class); 
      ri.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      context.startActivity(ri); 
    } 
} 


public class ReceiverActivity extends Activity 
{ 
    StringBuilder builder; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     Window win = getWindow(); 
     win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
       | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
     // Turn on the screen unless we are being launched from the AlarmAlert 
     // subclass as a result of the screen turning off. 
     win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 
       | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.launcher_layout); 
     builder = new StringBuilder(); 
     builder.append("onCreate called."); 
     Log.e("ReceiverActivity", "String : " + builder.toString()); 
    } 

    @Override 
    protected void onStart() { 
     Log.d("ReceiverActivity","Activity Life cycle - onStart called"); 
     super.onStart(); 
     builder.append("\nonStart called."); 
    } 

    @Override 
    protected void onResume() { 
     Log.d("ReceiverActivity","Activity Life cycle - onResume called"); 
     super.onResume(); 
     builder.append("\nonResume called."); 
     Log.e("ReceiverActivity", "String : " + builder.toString()); 
     ((TextView) findViewById(R.id.textView1)).setText(builder.toString()); 
    } 
    @Override 
    protected void onRestart() { 
     Log.d("ReceiverActivity","Activity Life cycle - onRestart called"); 
     super.onRestart(); 
    } 
    @Override 
    protected void onStop() { 
     Log.d("ReceiverActivity","Activity Life cycle - onStop called"); 
     super.onStop(); 
    } 
} 

感謝

+1

你的問題是什麼? – Simon

+0

問題是在屏幕空白期間,Activity似乎會通過onPause onResume週期進行很多,當您預期它不會? –

+0

@NeilTownsend,不會,但它會立即停止並重新啓動,爲什麼會發生這種情況? –

回答

相關問題