Android Question StartActivity does not open Activity2

rworner

Member
Licensed User
I am looking at building my first application with multiple activities. Using the samples from various threads I put the attached test app together. The main screen appears and allows me to select one of the three test buttons, but no matter which button I use the second activity does not appear on the screen. Did I miss a step?
 

Attachments

LucaMs

Expert
Licensed User
[To Erel]

I downloaded his project but saved it with a different name (xtest.zip) and maybe for this reason the number of views is still zero
upload_2019-10-18_14-58-2.png
 

rworner

Member
Licensed User
That fixed the issue of not displaying the WebView pointing to the URL - but when I click on the button at the top of Activity 2 to return to activity 1 it doesn't return. I have tried adding Activity.Finish before the StartActivity(Main) but it looks like I am being directed to Activity (main) Resume.

Another weird issue - when Activity 1 (main) begins if I don't click a button within 3-4 seconds the screen disappears and the log says
I was pointed to Activity (main) paused UserClosed=true -but I didn't touch the tablet???
 

LucaMs

Expert
Licensed User
I did not understand very well and the project you have attached contains only two activities, Main and Activity2. Possibly attach the project with the 3 activities.

However, normally a button is not needed to go back, the user will press the back key and return to the previous activity.
If instead you want to jump for example from the 2nd to the Main:
Activity.Finish
StartActivity (Main)
 

rworner

Member
Licensed User
There are 2 activities (main, Activity2). The main activity has 3 buttons each pointing to a different URL. When one of the three buttons is pressed it should call Activity2 and display a WebView with the correct URL. - All of that works. In Activity2 I have added a button at the top of the screen to return the user to the main activity when done with the WebView. The code is in lines 38-42 of Activity2. I have tried just the StartActivity(Main), and the Activity.Finish followed by the StartActivity(main) -- but neither returns me to the original display with the three buttons. It just stays on the WebView screen. The back button works, but I wanted to see how to move back and forth programmatically. The zip file with the code is attached.
 

Attachments

LucaMs

Expert
Licensed User
In Activity2 I have added a button at the top of the screen to return the user to the main activity when done with the WebView.
Not needed but ok.


It's working! You just need to create a better layout (A2 - using Designer AND ANCHORS)
 

klaus

Expert
Licensed User
You should keep Activity.Finish!
Your project works as expected when uncommenting Activity.Finish!
B4X:
Sub Button1b_Click
    Log("Hit Return")
    Activity.finish
    StartActivity(Main)
End Sub
Clicking on the button in Activity2 returns to Activity Main.
Clicking on another button in Activity Main shows the correct url in Activity2.
Tested on my Samsung Galaxy S8 with Android 9.
So what is your problem.
 

klaus

Expert
Licensed User
I think the layout of Activity2, Button1b.
I tested it with Button1b!
I agree with you that the layout is not perfect, the button height is quite small, but it works on my device.
The layout, is for me, another subject.
 

LucaMs

Expert
Licensed User
I tested it with Button1b!
I agree with you that the layout is not perfect, the button height is quite small, but it works on my device.
The layout, is for me, another subject.
but maybe he can't really click on it :)
 

rworner

Member
Licensed User
You should keep Activity.Finish!
Your project works as expected when uncommenting Activity.Finish!
B4X:
Sub Button1b_Click
    Log("Hit Return")
    Activity.finish
    StartActivity(Main)
End Sub
Clicking on the button in Activity2 returns to Activity Main.
Clicking on another button in Activity Main shows the correct url in Activity2.
Tested on my Samsung Galaxy S8 with Android 9.
So what is your problem.
When I click on one of the three buttons, it takes me to the proper URL, however when I click the button at the top of the screen to return, nothing happens and it just sits on the Activity2 page.
 

rworner

Member
Licensed User
It is working now on the tablet! I appreciate your assistance. I've been trying everything I could find searching the forum, but none of my searches brought up "Stoploading" - I doubt I would have found it.

Questions about the changes - 1 What did the anchoring affect? (Why was it necessary?)
2. As information -Is Webview1.Stoploading used anytime I have web content displayed and I want to leave to another activity/etc.?
 

kisoft

Well-Known Member
Licensed User
For me it works well on LG g6 (android 9). Use anchors and enlarge this button. Maybe it is too small for some phones.
You should also use CallSubDelayed. Also try to clear the ctrl+p project.
 
Last edited:

LucaMs

Expert
Licensed User
nothing happens and it just sits on the Activity2 page.
It happens because the webview is still downloading the page, this is why I wrote
WebView1.StopLoading is needed.
The project attached to my previous post (#14) works as expected.


1 What did the anchoring affect? (Why was it necessary?)
to adapt the layout on different displays.
Also, you shouldn't change the variant size, the button in Activity2 appeared too thin (its height) on my smartphone.
 
Last edited:
Top