I made an app that generates an alarm at 7 o'clock, it's catching on perfectly, the problem is when I get 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 get ? Well 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 is the Manifest, when I put the class Comofoiseudia.comoFoi
in the Main action, it takes normally, the problem is when I take the Main action, and I put another activity, there no more 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>