How to Set up Alarm Same like Alarm App in Android?

房东的猫 提交于 2019-12-11 00:03:34

问题


I am trying to setup alarm outside of my app with little popup box. I made that popup box by using Activity.I been trying for a long time to setup alarm like Alarm app but i get failed in some situations.

I am successful if i am exiting the app from the launch activity by using back button.

But when i press home button the alarm keep working charm but with last used activity in background.

I am not sure why this happening and i would like to know how i can make this work with out any activity in background when i pressed home button.

Here is my onReceiver Code.

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


    try {
         Bundle bundle = intent.getExtras();
         String message = bundle.getString("alarm_message");

         Intent newIntent = new Intent(context, ReminderPopupMessage.class);
         newIntent.putExtra("alarm_message", message);
         newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         context.startActivity(newIntent);
        } catch (Exception e) { 
         e.printStackTrace();

        }
}

}

If you guys provide the link for actual alarm app code that would be fabulous.

Thanks for your help guys.


回答1:


I found the answer after long time

Just Added this in Android Popup Class Manifest File.

 <activity android:name=".AlarmPopup" android:theme="@android:style/Theme.Dialog"
          android:clearTaskOnLaunch="true" android:launchMode="singleInstance" 
          android:finishOnTaskLaunch="true" excludeFromRecents="true"/>

The problem get solved.

I hope it will help for someone.




回答2:


Yes you should actually try src of Android alarm app here is the link.

have a look on my another answer here



来源:https://stackoverflow.com/questions/11393744/how-to-set-up-alarm-same-like-alarm-app-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!