2012-08-01 74 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)){ 

    } 
} 

}