Intent Play: Android: Reciever | Techbirds

Hi Folks,

TOday i will explain some common tasks that might be helpful while making android apps:

  • Call An Activity form Reciever

Intent i = new Intent(); i.setClassName(“com.example.gamedoc”, “com.example.gamedoc.OpenAppDialogActivity”); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_NEW_TASK ); context.startActivity(i)

Intent i = new Intent();

        i.setClassName(“com.example.gamedoc”,

                “com.example.gamedoc.OpenAppDialogActivity”);

        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_NEW_TASK );

        context.startActivity(i)

  • On Boot Completing, Starting a service:

public void startService() { try { if (intent == null) { intent = new Intent(Recieved_COntext, Teri_Service.class); } Calendar cal = Calendar.getInstance(); if (pIntent == null) { pIntent = PendingIntent.getService(mContext, 0, intent, 0); } if (alarms == null) { alarms = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); } alarms.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(), 400, pIntent); } catch (Exception e) { e.printStackTrace(); } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

public void startService() {

        try {

            if (intent == null) {

                intent = new Intent(Recieved_COntext, Teri_Service.class);

            }

            Calendar cal = Calendar.getInstance();

            if (pIntent == null) {

                pIntent = PendingIntent.getService(mContext, 0,

                        intent, 0);

            }

            if (alarms == null) {

                alarms = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);

            }

            alarms.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(),

                    400, pIntent);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

Kind Regards,

Tapan Saini

(Android Developer)

533 total views, 1 views today

Share this Onfacebook-8354218twitter-5224375linkedin-5724488google-7322602