-1

I have an Android app written in Delphi.

When launching the app and initializing another app by Intent, after closing the second app and going back to the first app, the first app is restarted.

Note: I saw that there is something about the onSaveState event, but I need my app not to restart because I use the return data from the second app in it.

I performed the initialization of the second app by Intent and when closing the second app, it should go back to the first one at a point where I can manipulate the Intent information where I opened the second app, but it is restarting the first app.

UPDATE: --//--//--//--//--//--// Here is my code:


procedure TForm1.btnEnviarTransacaoClick(Sender: TObject);
begin
   try
      var AURI:string:= 'payment-app://pay?return_scheme=retorno&amount=9999&editable_amount=0&transaction_type=credit';
      var AIntent: JIntent := TJIntent.Create;
      AIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW);
      AIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
      AIntent.setData(TJNet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(AURI))));
      TAndroidHelper.Activity.startActivityForResult(AIntent, 0);
      Timer1.Enabled:= True;
   except
      on E: Exception do begin
         TThread.Synchronize(nil, procedure
         begin
            lOG.D(E.Message);
         end);
      end;
   end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   Timer1.Enabled:= False;
   var ADLg:= TForm2.Create(Self);
   ADLg.Show;
end;

note: after start activity , I trigger a 4 second timer to create a new form and show it, but after finishing the second app and returning to the home app, the home app restarts. Sometimes debugging I managed to catch the exception:

> cant perform this action after onSaveInstanceState

this is my AndroidManifest, where to use explicit intent by scheme

{<activity
                android:name=".PaymentActivity"
                android:launchMode="singleTop"
                android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="pay-response"
                    android:scheme="retorno" />
            </intent-filter>
        </activity>}
  • Please show the actual code you are using to interact with the second app – Remy Lebeau Jul 27 '23 at 19:37
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 27 '23 at 22:51
  • @AlissonCristhian Next time, please don't provide your code in comments, you can [edit] your question instead to add more details as needed. I have done it for you this time. Also, can you please update your question to include the code for the 1st app that is handling the 2nd app's response to your Intent? What is your 1st app doing while waiting for the 2nd app to respond? – Remy Lebeau Jul 28 '23 at 01:07
  • I update my question. after start activity, i enable the timer for create new form and show. – Alisson Cristhian Jul 28 '23 at 12:12

1 Answers1

1

I found the problem:

in my AndroidManifest, the main activity was using launchmode: SingleTask, just change it to singletop that solved the problem.