Title acquisition in Android WEB view is strange when you move from page to page.

Asked 2 years ago, Updated 2 years ago, 143 views

Using WebView to create RSS readers.
I would like to use getTitle() to keep the information on the page I am currently viewing and bookmark it.
GetTitle does not work properly after page movement.

Out of Source onCreate

myWebView= (WebView) findViewById (R.id.webview);
    // Cancel standard browser
    myWebView.setWebViewClient(newWebViewClient());
    // URL to load when starting the application
    myWebView.loadUrl("http://lifehack2ch.livedoor.biz/");

Source Button Listener

String title=myWebView.getTitle();// Get the title of the web view you are looking at
        Log.d(title, "title");

·Log where you press the button on that page
D/Life Hack Channel 2 expression: title

·Logs that press the button after moving the page
I/WebView:FloatFade-run:Expired, go to STATE_NONE

If you have not moved from the initial page of the web view, the information is taken as intended.
If you click and move within the site, you will not be able to get any data.
Why?

android android-studio android-webview

2022-09-30 19:50

1 Answers

Similar actions have been taken without any problems.

Sample:

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android: orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:onClick="getTitle"
        android: text="Get Title!"/>

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

MainActivity.java:

private WebView webView;

@ Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    webView= (WebView) findViewById (R.id.webView);
    webView.setWebViewClient(newWebViewClient());
    webView.loadUrl("http://jp.stackoverflow.com/");
}

public void getTitle (View view) {
    Log.d("LOG_TAG", webView.getTitle());
}

LogCat:

 11-12 18:21:59.912 23382-23382/testapp D/LOG_TAG: Stack overflow
11-12 18:22:10.428 23382-23382/testapp D/LOG_TAG: New Questions - Stack Overflow

Isn't the problem (how to use the listener, etc.) somewhere else?


2022-09-30 19:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.