• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps (Help) Pressing back on webview fragment activity does not go back to previous page

Hello.
I have an app that has fragment activities with webview and a navigational drawer. When I press back it goes to a previous fragment activity but it does not go back to the previous page on the webview.

The code on MainActivity.java:
Java:
 @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.nav_facebook:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new FacebookFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_twitter:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new TwitterFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_instagram:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new InstagramFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_linkedin:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new LinkedinFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_snapchat:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new SnapchatFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_pinterest:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new PinterestFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_youtube:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new YoutubeFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_about:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new AboutFragment()).addToBackStack("tag").commit();
                break;
            case R.id.nav_privacy:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new PrivacyFragment()).addToBackStack("tag").commit();
                break;
        }

        drawer.closeDrawer(GravityCompat.START);

        return true;
    }


    @Override
    public void onBackPressed() {
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStack();
        } else {
            super.onBackPressed();
        }
    }

The code in one of the fragments (FacebookFragment.java):
Java:
public class FacebookFragment extends Fragment {
    public FacebookFragment() {

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_facebook, container, false);
        WebView webView = (WebView)v.findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("https://www.facebook.com/");
        return v;



    }





}

Help superSU problem

I flashed a custom rom

It's more likely a bug or issue in the custom ROM you're using, rather than anything to do with superSU, As long as you're using the correct ROM that was built for your particular phone or tablet, it could be something that the ROM dev needs to fix.

A few years ago I had it happen when I was using a build of CynogenMod on an Oppo Find 7, the WiFi wasn't working, that was also reported by others, and the dev did fix it with an update.

How to draw and move text and image on canvas with java on android?

Hi
I have an university project with canvas but i can not already do it. I have to create a canvas area which has height max 200px top of an activity and i have to able to add text and image to canvas and move them. Then i have to take a bitmap from canvas and save it. I attached a example image of app's activity. Could you please give me an advice or example.

Best and Kind Regards.

canvas.png

LoadURL onReceivedError() not firing

and neither does this:-
Code:
package com.example.lilaccottagebell

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.webkit.WebResourceError
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create the NotificationChannel
            val name = getString(R.string.channel_name)
            val descriptionText = getString(R.string.channel_description)
            val importance = NotificationManager.IMPORTANCE_DEFAULT
            val CHANNEL_ID = "only_channel"
            val mChannel = NotificationChannel(CHANNEL_ID, name, importance)
            mChannel.description = descriptionText
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.createNotificationChannel(mChannel)
        }



        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create channel to show notifications.
            val channelId = getString(R.string.default_notification_channel_id)
            val channelName = getString(R.string.default_notification_channel_name)
            val notificationManager = getSystemService(NotificationManager::class.java)
            notificationManager?.createNotificationChannel(NotificationChannel(channelId,
                    channelName, NotificationManager.IMPORTANCE_HIGH))
        }

        // If a notification message is tapped, any data accompanying the notification
        // message is available in the intent extras. In this sample the launcher
        // intent is fired when the notification is tapped, so any accompanying data would
        // be handled here. If you want a different intent fired, set the click_action
        // field of the notification message to the desired intent. The launcher intent
        // is used when no click_action is specified.
        //
        // Handle possible data accompanying notification message.
        // [START handle_data_extras]

        // [END handle_data_extras]

        val myWebView: WebView = findViewById(R.id.webview)

        /*myWebView.loadUrl("https://amazon.co.uk")*/
        myWebView.webViewClient = WebViewClient()
        myWebView.setWebViewClient(object : WebViewClient() {
            fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String, getContext: Context) {
                Log.i("WEB_VIEW_TEST", "error code:$errorCode")
                Toast.makeText(getContext, "Webcam not reachable",Toast.LENGTH_SHORT ).show()

            }
        })
        WebView.setWebContentsDebuggingEnabled(true)
        /*5 March 2021*/
        myWebView.clearCache(true)






        myWebView.loadUrl("http://192.168.1.144/apikey/webcam")

        val disable_button: Button = findViewById(R.id.disable)
        disable_button.setOnClickListener {
            myWebView.loadUrl("http://192.168.1.144/apikey/disable")

        }

        fun onReceivedError(
                view: WebView,
                request: WebResourceRequest,
                error: WebResourceError
        ) {
            Toast.makeText(this, "Webcam not reachable", Toast.LENGTH_SHORT).show()
        }




    }


}

Filter

Back
Top Bottom