2012-08-01 27 views
0

在我的android應用程序中,我開始使用廣播接收器的活動。如果此活動期間,如果我解鎖我的設備鎖定,則活動重啓意味着它運行在再次創造 請幫我解決這個問題提前解鎖android設備時的Activity重啓動

+0

你在LogCat中得到什麼 – 2012-08-01 08:53:44

+0

你實現了'onPause();'和/或'onStop();'方法嗎?如果是的話,你保存應用程序狀態?你正在使用什麼設備? – meeDamian 2012-08-01 08:55:18

+0

我已經在創建方法中添加了烤麪包,並且每當我解鎖設備時,我都會獲得 – nvavadiya 2012-08-01 08:56:56

回答

0

什麼在AndroidManifest.xml您的活動宣言

感謝? 我覺得你應該任命launchMode爲 「singleTask」 這樣的:

<activity android:name=".Youracticity" android:launchMode="singleTask" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait"> 
</activity> 

^-^

+0

感謝它爲我工作。 – nvavadiya 2012-08-01 09:28:42

+0

現在我使用這個解決方案後有一個問題。在活動中,我在全屏顯示視頻,但在我解鎖設備視頻無法在全屏幕中看到 – nvavadiya 2012-08-01 09:39:04

0

在你的清單你有這樣的事:

<action android:name="android.intent.action.USER_PRESENT" /> 

     <receiver android:name="com.activities.app" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 

如果是,那麼請妥善處理。

0

用於檢測屏幕上,屏幕關閉註冊廣播reciver,如:

<receiver android:name="receiverScreen"> 
    <intent-filter> 
     <action android:name="android.intent.action.SCREEN_ON" /> 
     <action android:name="android.intent.action.SCREEN_OFF" /> 
<action android:name="android.Intent.ACTION_USER_PRESENT" /> 
    </intent-filter> 
</receiver> 

在活動或服務:

try { 
      IntentFilter if= new IntentFilter(Intent.ACTION_SCREEN_ON); 

      if.addAction(Intent.ACTION_SCREEN_OFF); 
if.addAction(Intent.ACTION_USER_PRESENT); 

      BroadcastReceiver mReceiver = new receiverScreen(); 

      registerReceiver(mReceiver, if); 
    } catch (Exception e) { 

    } 

接收器代碼中的系統,如果屏幕上通知你/ off發生:

public class receiverScreen extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ 

    } 
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){ 

    } 
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){ 

    } 
} 

} 
相關問題