Android Question Return from activity

Massimo66

Member
Hi, i'm new.
i have the first activity es: ORDER with a table,
With bnt_click i open a second activity es: CARICO that do something.
When i close the Activity CARICO, i want return to the first and refresh the table.
I try to call the sub that requery the table on the ORDER->Activity_Resume but don't run.
Thanks
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
@Erel is correct, B4XPages will simplify your process.

But, to answer your question: When you call the second activity, the first activity is not "suspended" and waiting for a return from your second activity. The first activity ends and the second activity starts. When the second activity ends, there is no place to go back to in the first, it completely restarts the first activity.

The second activity would need to set or populate an object that the first activity could evaluate in Activity_Create/Activity_Resume and use it to update the information as needed.
 
Upvote 0

Massimo66

Member
i tried in debug and when the second activity ends, it doesn't go back to the first activity->btn_click nor go through resume.
Erel recommends switching to B4XPages.
In practice, once the second activity is finished, I should repopulate the table with the updated rows.
Thank you
 
Upvote 0

Massimo66

Member
Don't waste your time with activities. Switch to B4XPages.
Don't waste your time with activities. Switch to B4XPages.
Hi Erel, I'm starting a new app in B4xPages. I'm having a problem with TakePhoto: after taking the photo, the current page closes and the app returns to the MainPage, while I'd like it to stay on the current page. Here's the code:
TakePicture:
Private Sub TakePicture (TargetWidth As Int, TargetHeight As Int)
    Dim i As Intent
    i.Initialize("android.media.action.IMAGE_CAPTURE", "")
    File.Delete(Provider.SharedFolder, tempImageFile)
    Dim u As Object = Provider.GetFileUri(tempImageFile)
    i.PutExtra("output", u) 'the image will be saved to this path
        
    Try
        Wait For (CallSub(KeepRunningService, "Start")) Complete (Unused As Boolean)
        StartActivityForResult(i)
        'B4XPages.GetManager.SetActivityPausedEvent("HandleCameraResult")
        
        Wait For ion_Event (MethodName As String, Args() As Object)
        CallSub(KeepRunningService, "Stop")
        Dim bmp As B4XBitmap
        If -1 = Args(0) Then
            Try
                Dim in As Intent = Args(1)
                If File.Exists(Provider.SharedFolder, tempImageFile) Then
                    Dim Exif As ExifData
                    Exif.Initialize(Provider.SharedFolder, tempImageFile)
                    bmp = LoadBitmapSample(Provider.SharedFolder, tempImageFile, Max(TargetWidth, TargetHeight), Max(TargetWidth, TargetHeight))
                    Log("Orientation: " & Exif.getAttribute(Exif.TAG_ORIENTATION))
                    Select Exif.getAttribute(Exif.TAG_ORIENTATION)
                        Case Exif.ORIENTATION_ROTATE_180 '3
                            bmp = bmp.Rotate(180)
                        Case Exif.ORIENTATION_ROTATE_90 '6
                            bmp = bmp.Rotate(90)
                        Case Exif.ORIENTATION_ROTATE_270 '8
                            bmp = bmp.Rotate(270)
                    End Select
                    bmp = bmp.Resize(TargetWidth, TargetHeight, True)
                Else If in.HasExtra("data") Then 'try to get thumbnail instead
                    Dim jo As JavaObject = in
                    bmp = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data"))
                End If
            Catch
                Log(LastException)
            End Try
        End If
        CallSubDelayed3(Me, "Image_Available", bmp.IsInitialized, bmp)
        'File.Copy(Provider.SharedFolder, tempImageFile,File.DirRootExternal & "/Download",tempImageFile)
        Dim cvstest As Canvas
        Dim rctTest As Rect
        cvstest.Initialize(ImageView1)
        
        Exif.Initialize(Provider.SharedFolder, tempImageFile)
        Dim temp As String = Exif.getAttribute(Exif.TAG_DATETIME)
        
        rctTest.Initialize(0, 0, ImageView1.Width, ImageView1.Height)
        cvstest.DrawBitmap(LoadBitmap(Provider.SharedFolder, tempImageFile), Null, rctTest)
        'cvstest.DrawText("Scattata il " & DateTime.Date(DateTime.Now) &" " & DateTime.Time(DateTime.now), 10dip, 30dip, Typeface.DEFAULT, 12, Colors.Green, "LEFT")
        cvstest.DrawText("Scattata il :" & temp, 2dip, 14dip, Typeface.DEFAULT, 12, Colors.Green, "LEFT")
    
        Private Out As OutputStream
        Out = File.OpenOutput(File.DirRootExternal & "/Download",Global.GetTempFilename("jpg"), False)
        cvstest.Bitmap.WriteToStream(Out, 100, "PNG")
        Out.Close
        
        
    Catch
        ToastMessageShow("Camera is not available.", True)
        Log(LastException)
        CallSubDelayed3(Me, "Image_Available", False, Null)
    End Try
End Sub


Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = Me
    jo = jo.RunMethod("getBA", Null)
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array(ion, i))
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…