android - Accessing MainActivity once BOOT_COMPLETE is received -
i have reminder app notify me @ given time when next reminder array of objects due.
i trying make set notification again on boot.
i have boot receiver set in manifest, how access information mainactivity once phone has booted, given app hasn't been opened yet?
i hoping use -
public class bootreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { log.i("regularreminders","onreceive"); new mainactivity().setnotifications(); } }
but returns null error within notification once tries run method in mainactivity, app crashes emulator boots , see in logcat -
java.lang.runtimeexception: unable start receiver com.androidandyuk.regularreminders.bootreceiver: java.lang.nullpointerexception: attempt invoke virtual method 'int java.util.arraylist.size()' on null object reference
this points line -
if (reminders.size() >= 0) {
i did wonder if save notification message sharedprefs , call in receiver, got errors of null object reference doing too.
i tried sending broadcast adding info, guess receiver set in mainactivity isn't listening app hasn't been run?
i know google protecting malware, not letting them after book, there way round can set notification after reboot?
thanks.
although can't access variables mainactivity, can access sharedpreferences , sqlite database used in app, in case made new array , read database , worked on that.
wiki
Comments
Post a Comment