0

I am facing issue in Activity which is calling from Broadcast receiver.

My application contains alarm system, so when time of alarm match, at that time, broadcast receiver calls one activity to get in front. This activity is not in full screen, it is one type of alert box using RegionSearchDialog as theme. (Don't be confuse, I am using activity only, my class extends activity, but the theme in xml set as RegionSearchDialog)

My platform of development is: 4.0.4

Now my issue is: if my device is on (unlock keygurad) either application is in front or in back, it works fine. But if power is off (sleep mode / device is lock), it will call same activity, onCreate() calls first then onResume() and then it will call onPause() as my device is in sleep mode.

I want to keep that activity running, don't want to get it sleep.

So, when alarm time match, it will buzz alarm and if its in sleep mode then user can unlock device and see popup of that alarm.

Thanks in advance to help me in that.

Kinnar Vasa
  • 397
  • 1
  • 9
  • here i found good example for services http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging – jitendra Mar 03 '14 at 12:48

3 Answers3

1

This is the way Activities in Android are supposed to work. You would be better using a Service or using the Alarm manager to launch an Activity at a certain time as these are more suited to what you are trying to do =).

dmon
  • 30,048
  • 8
  • 87
  • 96
Con
  • 368
  • 1
  • 7
0

Here is my code,i think it can help you: In your activity on create():

 super.onCreate(savedInstanceState);
  final Window win = getWindow();
  win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
  | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  setContentView(R.layout.main); 

and main xml is:

<activity
android:name=".main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar"

android:launchMode="singleInstance" 
android:excludeFromRecents="true"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation" />

pls test these code in your project. :)

enjoy-writing
  • 520
  • 3
  • 4
-1

In addition to the response by 'enjoy-writing':

  1. It sufficed in my android app to set the flags as described in the onCreate code.
  2. The effect was that the app would pause when going into sleep mode (e.g. through pressing the On/off button on the phone), and resume when returning from sleep mode.
  3. By removing the FLAG_KEEP_SCREEN_ON flag you can still have the phone fall asleep if the view isn't used for a while.
George Stocker
  • 57,289
  • 29
  • 176
  • 237