Wie kann man dass machen, dass eine app (mit android studio erstellt) beim zweiten start eine andere activity ausführt(Passwort merken Funktion)?

...komplette Frage anzeigen

2 Antworten

Mal davon abgesehen, dass ein Browser wie Chrome wahrscheinlich die bessere Performance als eine WebView bietet, kannst du das mit SharedPreferences machen.

http://stackoverflow.com/questions/23024831/android-shared-preferences-example

Antwort bewerten Vielen Dank für Deine Bewertung
Tomixd3 23.05.2016, 19:27

könntest du mir dass vielleicht auch an meinem Code zeigen? Da ich es nicht so richtig hin bekomme.

0
heilwigkenner 23.05.2016, 19:32
@Tomixd3

Was ist denn der Fehler?

Statt den Text aus den TextViews zu holen, lädst du halt den aus den SharedPreferences.

0
Tomixd3 23.05.2016, 19:36
@heilwigkenner

1. Er erkennt editor nicht und 2. verstehe ich nicht, wie ich dass mit username und Password machen soll

0
heilwigkenner 23.05.2016, 20:16
@Tomixd3

Ok, aber wo funktioniert das nicht? Du lädst die SharedPreferences ja gar nicht.

0
Tomixd3 23.05.2016, 20:27
@heilwigkenner

Also ich schick gleich nochmal den code, aber das problem ist, dass ich nicht weiß wie ich dass machen muss, dass es sich mit dem
(durch sharedpreferences) gespeicherten username und password einloggt statt mit dem was ich in der url angegeben habe.

Code:

package de.schule.plan;

import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

private EditText username;
private EditText password;
private Button login;
private TextView loginLockedTV;
private TextView attemptsLeftTV;
private TextView numberOfRemainingLoginAttemptsTV;
private TextView textView1;
private TextView textView2;
private TextView textView3;
private WebView webView;
int numberOfRemainingLoginAttempts = 10000000;
int visibility;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupVariables();
}
private void setupVariables() {
username = (EditText) findViewById(R.id.usernameET);
password = (EditText) findViewById(R.id.passwordET);
login = (Button) findViewById(R.id.loginBtn);
loginLockedTV = (TextView) findViewById(R.id.loginLockedTV);
attemptsLeftTV = (TextView) findViewById(R.id.attemptsLeftTV);
numberOfRemainingLoginAttemptsTV = (TextView) findViewById(R.id.numberOfRemainingLoginAttemptsTV);
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));

}

public static final String MY_PREFS_NAME = "MyPrefsFile";

public void authenticateLogin(View view) {
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();

if (username.getText().toString().equals("schule") &&
password.getText().toString().equals("schule")) {
editor.putString("username", "schule");
editor.putString("password", "schule");
editor.commit();
username.setVisibility(View.INVISIBLE);
password.setVisibility(View.INVISIBLE);
login.setVisibility(View.INVISIBLE);
loginLockedTV.setVisibility(View.INVISIBLE);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("http://osp:schule@www....de");
webView.setVisibility(visibility);
WebSettings settings = webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
return false;
}
});

} else {
Toast.makeText(getApplicationContext(), "Falsches Passwort!",
Toast.LENGTH_SHORT).show();
numberOfRemainingLoginAttempts--;
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));

if (numberOfRemainingLoginAttempts == 0) {
login.setEnabled(false);
loginLockedTV.setVisibility(View.VISIBLE);
loginLockedTV.setBackgroundColor(Color.RED);
loginLockedTV.setText("LOGIN LOCKED!!!");
}
}

} else {
username.setVisibility(View.INVISIBLE);
password.setVisibility(View.INVISIBLE);
login.setVisibility(View.INVISIBLE);
loginLockedTV.setVisibility(View.INVISIBLE);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("http://username:password@www....de");
webView.setVisibility(visibility);
WebSettings settings = webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
return false;
}
});
}
}
}
0
package de.schule.plan;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

private EditText username;
private EditText password;
private Button login;
private TextView loginLockedTV;
private TextView attemptsLeftTV;
private TextView numberOfRemainingLoginAttemptsTV;
private TextView textView1;
private TextView textView2;
private TextView textView3;
private WebView webView;
int numberOfRemainingLoginAttempts = 10000000;
int visibility;

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

public void authenticateLogin(View view) {
if (username.getText().toString().equals("schule") &&
password.getText().toString().equals("schule")) {

username.setVisibility(View.INVISIBLE);
password.setVisibility(View.INVISIBLE);
login.setVisibility(View.INVISIBLE);
loginLockedTV.setVisibility(View.INVISIBLE);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("http://schule:schule@www.......de");
webView.setVisibility(visibility);
WebSettings settings = webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
return false;
}
});

} else {
Toast.makeText(getApplicationContext(), "Falsches Passwort!",
Toast.LENGTH_SHORT).show();
numberOfRemainingLoginAttempts--;
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));

if (numberOfRemainingLoginAttempts == 0) {
login.setEnabled(false);
loginLockedTV.setVisibility(View.VISIBLE);
loginLockedTV.setBackgroundColor(Color.RED);
loginLockedTV.setText("LOGIN LOCKED!!!");
}
}
}

private void setupVariables() {
username = (EditText) findViewById(R.id.usernameET);
password = (EditText) findViewById(R.id.passwordET);
login = (Button) findViewById(R.id.loginBtn);
loginLockedTV = (TextView) findViewById(R.id.loginLockedTV);
attemptsLeftTV = (TextView) findViewById(R.id.attemptsLeftTV);
numberOfRemainingLoginAttemptsTV = (TextView) findViewById(R.id.numberOfRemainingLoginAttemptsTV);
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));

}

}
Antwort bewerten Vielen Dank für Deine Bewertung

Was möchtest Du wissen?