I
I
Igor A2018-02-18 23:53:50
Java
Igor A, 2018-02-18 23:53:50

How to use an object in an activity in another object?

Good day.
There is MainActivity (class), several objects are created in it, including webView.
AlertDialog is created when you click on the button (from the menu) "EXIT".
You need to exit not from the application, but from the web user interface.
To do this, you need to delete cookies (authorization token) and redirect to the main page.
The problem is that I don't know how to properly use the created objects inside another class. For example in AlertDialog. Everything works within one activity. No others.
Example:

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.AlertDialogStyle);

            builder.setMessage("Вы уверены?")
                         .setCancelable(true)
                         .setNegativeButton("Нет", new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                             }
                 })
                .setPositiveButton("Да", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                            // удаляем сессию авторизации.
                      android.webkit.CookieManager
                              .getInstance()
                              .setCookie(Constants.DOMAIN_COOKIE, "q=");
                            MainActivity.this.webView.loadUrl("/");
                      }
                });
  builder.create();
    builder.show();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question