Alarm manager, main screen

Asked

Viewed 102 times

0

I made an app that generates an alarm at 19 hours, is picking up perfectly, the problem is when I pull this alarm from the Main Activity in Manifest, when I do this, the app no longer generates the alarm, what do I need to do to catch? Because my app has many screens.

Code of the class I want in the Main action:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frase_ativar);

        btAtivar = (Button) findViewById(R.id.btAtivar);

        //VERIFICA SE JA TEM ASSISTENTE
        assistenteAtivar();

        btAtivar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(FraseAtivar.this, Cadastro.class);
                startActivity(intent);
            }
        });

    }

    private void assistenteAtivar(){

        Preferencias preferencias = new Preferencias(FraseAtivar.this);
        nomedoAssistente = preferencias.getNomeDoAssistente();
        nomedoHumano = preferencias.getNomeDoHumano();
        if(nomedoAssistente != null || nomedoHumano != null){
            AbirTelaPrincipal();

        }


    }

    private void AbirTelaPrincipal(){
        Intent intent = new Intent(FraseAtivar.this, TelaPrincipal.class);
        startActivity(intent);
        finish();
    }


}

Alarm code:

public class comoFoi extends AppCompatActivity {

    AlarmManager alarmManager;
    private PendingIntent pending_intent;



    private AlarmReceiver alarm;


    comoFoi inst;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_como_foi);


        this.context = this;


        final Intent myIntent = new Intent(this.context, AlarmReceiver.class);

        // Codigo para o serviço de alarme
        alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

        // bota o seu calendario, com o calendario do android
        final Calendar calendar = Calendar.getInstance();



        calendar.add(Calendar.SECOND, 3);
        calendar.set(Calendar.HOUR_OF_DAY, 19);
        calendar.set(Calendar.MINUTE, 55);

        myIntent.putExtra("extra", "yes");
        pending_intent = PendingIntent.getBroadcast(comoFoi.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);



        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending_intent);

        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY,
                pending_intent);




        }


    }

Here’s the Manifest, when I make you class Comofoiseudia.comoFoi in the Main action, it usually picks up, the problem is when I take off the Main action, and I put another Activity, then no longer picks up the 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/AppTheme">
    <activity android:name=".Comofoiseudia.comoFoi">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Cadastro" />
    <activity android:name=".TelaPrincipal" />
    <activity android:name=".FraseAtivar" />
    <activity android:name=".AgendamentoCompromisso" />
    <activity android:name=".comoFoi" />


    <receiver android:name=".Comofoiseudia.AlarmReceiver" />


    <service
        android:name=".Comofoiseudia.Som"
        android:enabled="true"></service>

    <service
        android:name=".Comofoiseudia.BootService"></service>



    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>




</application>
  • Put the main screen code here, so it’s hard to know what’s going on.

  • I’ve already edited legal now

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.