Android app freeze when keyboard is shown after using NotificationCenter

  

I have a huge app made on Delphi (Berlin) and now I got an issue that I cannot solve:

After presenting a simple notification using the TNotificationCenter the app continues to work fine, everything is OK, but when the user taps an Edit the app freezes right after the keyboard is shown, the keyboard still working but the app is frozen. Or, if the user had opened the keyboard on any Edit before and the app present a notification, the app freezes before the notification is shown.

The only way I found to prevent this is commenting the line:

NotificationCenter1.PresentNotification(MyNotification);

So the only solution for my app is remove all notifications or re-made on another development platform?

Anyone got a hint?

Edit:

So, the Native Edit doesn’t solve my problem, actually it make the app freeze right after the notification is shown event without tapping the Edit.

Then, I removed all main Form.OnShow events, all main Form.OnVirtualKeyBoardHidden and main Form.OnVirtualKeyBoardShown events, all main Form.KeyUp events, all kind of events from a specific Edit and tried it. App still freezing;

The 8 sec Timer that presents the Notification:

procedure TForm1.Timer3Timer(Sender: TObject);
var
I,Brk:integer;
RaioCemMetros:string;
RaioMetrosF:double;
Notif:boolean;
aDay: TDateTime;
aaStart,aaFinish: TTime;
DayOk:boolean;
HoraStart,MinStart,HoraFim,MinFim:string;
Dia,Mes,Ano:string;
Tipo: string;
Dayofwk: integer;
Navig:string;
begin
Label1.Text := ‘1 ‘+DownloadedAlerts.Text;
Brk := 0;
Notif := False;
if ((CityBackground.Tag = 0) and (IdDownloadClient.Tag = 0) and (Form58.Image1.Tag = 0) and (Form64.Image1.Tag = 0) and (TabControl1.TabIndex = 0) and (DownloadedAlerts.Text <> ”) and (LastNotifON = False) and (NotifOn)) then
begin
Label1.Text := ‘2’;
LatS := StringReplace(lat,’.’,’,’,[rfReplaceAll, rfIgnoreCase]);
LongS := StringReplace(long,’.’,’,’,[rfReplaceAll, rfIgnoreCase]);
LatF := StrToFloat(LatS);
LongF := StrToFloat(LongS);

for I := 0 to DownloadedAlerts.Count-1 do
begin
Brk := I;
EventLatURL := Copy(DownloadedAlerts[I],2,16);
EventLongURL := Copy(DownloadedAlerts[I],19,16);
EventLatS := StringReplace(EventLatURL,’.’,’,’,[rfReplaceAll, rfIgnoreCase]);
EventLongS := StringReplace(EventLongURL,’.’,’,’,[rfReplaceAll, rfIgnoreCase]);
EventLatF := StrToFloat(EventLatS);
EventLongF := StrToFloat(EventLongS);
DistanciaV := abs(LatF-EventLatF);
DistanciaH := abs(LongF-EventLongF);

distanciaGPS := sqrt(sqr(DistanciaV) + sqr(DistanciaH));
distanciaMETROS := distanciaGPS*(111120*0.946);

RaioCemMetros := Copy(DownloadedAlerts[I],55,4);
RaioMetrosF := 100*StrToFloat(RaioCemMetros);

if RaioMetrosF >= distanciaMETROS then
begin
Label1.Text := ‘3’;
DayOk := False;
Dayofwk := DayOfTheWeek(Now);
case Dayofwk of
7: if (ansipos(‘11111111’,DownloadedAlerts[I]) > 0) then DayOk := True; // Domingo
1: if (ansipos(‘22222222’,DownloadedAlerts[I]) > 0) then DayOk := True;
2: if (ansipos(‘33333333’,DownloadedAlerts[I]) > 0) then DayOk := True;
3: if (ansipos(‘44444444’,DownloadedAlerts[I]) > 0) then DayOk := True;
4: if (ansipos(‘55555555’,DownloadedAlerts[I]) > 0) then DayOk := True;
5: if (ansipos(‘66666666’,DownloadedAlerts[I]) > 0) then DayOk := True;
6: if (ansipos(‘77777777’,DownloadedAlerts[I]) > 0) then DayOk := True;
end;

if (ansipos(‘99999999’,DownloadedAlerts[I]) > 0) then DayOk := True;
if ((DayOk = False) and (DownloadedAlerts[I].Contains(‘11111111’) = False) and (DownloadedAlerts[I].Contains(‘22222222’) = False) and
(DownloadedAlerts[I].Contains(‘33333333’) = False) and (DownloadedAlerts[I].Contains(‘44444444’) = False) and
(DownloadedAlerts[I].Contains(‘55555555’) = False) and (DownloadedAlerts[I].Contains(‘66666666’) = False) and
(DownloadedAlerts[I].Contains(‘77777777′) = False)) then
begin
Dia := Copy(DownloadedAlerts[I],36,2);
Mes := Copy(DownloadedAlerts[I],38,2);
Ano := Copy(DownloadedAlerts[I],40,4);
aDay := StrToDate(Dia+’/’+Mes+’/’+Ano);
if aDay = Today then DayOk := True;
end;
if DayOk then
begin
HoraStart := Copy(DownloadedAlerts[I],45,2);
MinStart := Copy(DownloadedAlerts[I],47,2);
HoraFim := Copy(DownloadedAlerts[I],50,2);
MinFim := Copy(DownloadedAlerts[I],52,2);

aaStart:= StrToTime(HoraStart+’:’+MinStart+’:00′);
aaFinish := StrToTime(HoraFim+’:’+MinFim+’:59′);

if (TimeInRange(Now,aaStart,aaFinish)) = True then
begin
Label1.Text := ‘4’;
Tipo := Copy(DownloadedAlerts[I],1,1);
Navig := Copy(DownloadedAlerts[I],35,1);
Application.ProcessMessages;
Notificationn := NotificationCenter1.CreateNotification;
try
if ((Tipo <> ‘p’) and (Tipo <> ‘c’)) then
begin
LastNotifOn := True;
LastNotifLat := EventLatS;
LastNotifLong := EventLongS;
Label6.Text := Copy(DownloadedAlerts[I],60,ansipos(‘|’,DownloadedAlerts[I])-60);
if distanciaMETROS >= 1000 then Label7.Text := FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de distância agora’ else
Label7.Text := FloatToStr(RoundTo(distanciaMETROS,1))+’ metros de distância agora’;
Label9.Text := ‘Alerta às ‘+IntToStr(HourOfTheDay(Now))+’h ‘+IntToStr(MinuteOfTheHour(Now))+’m’;
Label10.Text := Copy(DownloadedAlerts[I],ansipos(‘|’,DownloadedAlerts[I])+1,DownloadedAlerts[I]. Length-ansipos(‘|’,DownloadedAlerts[I]));
RoundRect1.Visible := True;
RoundRect1.Opacity := 1.0;
Rectangle5.Visible := True;
Rectangle5.Opacity := 1.0;
end;
Notif := True;
Image2.Visible := True;
Label3.Visible := True;
Button8.Visible := True;
Notificationn.Name := ‘Name’;
if Tipo = ‘h’ then begin
Notificationn.Title := ‘Alerta de Check-out’;
Notificationn.AlertBody := ‘Hotel há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if ((Tipo = ‘n’) and (Parado)) then begin
Notificationn.Title := ‘Alerta de Área’;
Notificationn.AlertBody := ‘Área com chamados reduzidos’; // Primeira mensagem, que some em 1 segundo
end else
if Tipo = ‘o’ then begin
Notificationn.Title := ‘Alerta de Hospital’;
Notificationn.AlertBody := ‘Hospital há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘b’ then begin
Notificationn.Title := ‘Alerta de Balada’;
Notificationn.AlertBody := ‘Saída de balada há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘f’ then begin
Notificationn.Title := ‘Alerta de Partida’;
Notificationn.AlertBody := ‘Saída de torcedores há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘i’ then begin
Notificationn.Title := ‘Alerta de Igreja’;
Notificationn.AlertBody := ‘Missa próxima do fim há menos de ‘+FloatToStr(RoundTo(distanciaMETROS,1))+’ metros de você’;
end else
if Tipo = ‘s’ then begin
Notificationn.Title := ‘Alerta de Show’;
Notificationn.AlertBody := ‘Show de música há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘e’ then begin
Notificationn.Title := ‘Alerta de Evento’;
Notificationn.AlertBody := ‘Evento há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘m’ then begin
Notificationn.Title := ‘Motorista Ajudante’;
Notificationn.AlertBody := ‘Mensagem do Motorista Ajudante’;
end else
if Tipo = ‘u’ then begin
Notificationn.Title := ‘Alerta de Alunos’;
Notificationn.AlertBody := ‘Saída de alunos há menos de ‘+FloatToStr(RoundTo(distanciaMETROS/1000,-1))+’ km de você’;
end else
if Tipo = ‘p’ then begin
Notificationn.Title := ‘Posto em promoção’;
Notificationn.Name := ‘Promocao’;
Notificationn.AlertBody := ‘Combustível em promoção reportado por um motorista há ‘+FloatToStr(RoundTo(distanciaMETROS,1))+’ metros de você.’;
end else
if Tipo = ‘c’ then begin
Notificationn.Title := ‘Chamado suspeito!’;
Notificationn.Name := ‘Chamado’;
Notificationn.AlertBody := ‘Solicitação suspeita foi reportada por um motorista nesta região.’;
end;
if Navig = ‘6’ then begin
Image2.Visible := False;
Label3.Visible := False;
Button8.Visible := False;
end;
Label1.Text := ‘5’;
Notificationn.EnableSound := False;
Application.ProcessMessages;
Label1.Text := ‘6’;
NotificationCenter1.PresentNotification(Notificationn); // <<< Removing this line solves everything, but no Android notification is sent to the user
Label1.Text := ‘7’;
if NotifAudio = True then begin
MediaPlayer1.FileName := (TPath.GetDocumentsPath + PathDelim + ‘iclassy.mp3’);
MediaPlayer1.Play;
end;
finally
Label1.Text := ‘8’;
Notificationn.DisposeOf;
Label1.Text := ‘9’;
end;
end;
end;
end;
if Notif = True then Break;
end;
if Notif = True then
begin
Timer3.Tag := 0;
try
Label1.Text := ’10’;
DownloadedAlerts.Delete(Brk);
Label1.Text := ’11’;
except
Label1.Text := ‘Except’;
end;
end else Timer3.Tag := 1;
if ((Tipo = ‘p’) or (Tipo = ‘c’)) then
begin
LastNotifON := False;
Timer3.Tag := 1;
end;
end;
end;

All “Label1.Text := ‘XX'” is for debugging purposes.

Anyone had that issue with TNotificationCenter before?

PS: Embarcadero Delphi Berlin / Android platform

PS2: AndroidManifest http://txt.do/dk987

PS3: The notification works fine Screenshot

Comments are closed.