Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

alarmmanager - Alarm manager for Android Oreo +

IM having a problem with Alarm manager for android oreo and upper versions the alarm works fine when the app is opened and in the background...

BUT when i close the app the alarm wont get triggered at all Here is my MainActivity >>> 'class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    var intent=Intent(this,mybro::class.java)

    var pending_intent=PendingIntent.getBroadcast(this,11,intent,0)

    var alarm=getSystemService(Context.ALARM_SERVICE) as AlarmManager

    alarm.setExactAndAllowWhileIdle(
            AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + (10*1000),pending_intent
    )

}

}'

And here is my BroadCastReciver 'class mybro : BroadcastReceiver() {

override fun onReceive(context: Context?, intent: Intent?) {


    Toast.makeText(context,"HEllO",Toast.LENGTH_SHORT).show()
}

}'

And here is my AndroidManifest '

<uses-permission android:name="android.permission.SET_ALARM" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.ServicesTRYS">


    <receiver android:name=".mybro"
        android:exported="false"
        />

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

'

So Why is this happening and how to Solve this problem

question from:https://stackoverflow.com/questions/65854688/alarm-manager-for-android-oreo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...