我有我的活動意圖啓動的問題。看來,當我在autoGO方法運行這段代碼兩個活動奇怪開始
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, contentScreen.class);
startActivity(intent);
finish();
,它運行兩個活動,我知道這是我的logcat的告訴我:
11-03 11:16:16.542: INFO/ActivityManager(58): Displayed activity three.three/.contentScreen: 2030 ms (total 3391 ms)
11-03 11:16:16.713: INFO/ActivityManager(58): Displayed activity three.three/.contentScreen: 1596 ms (total 1596 ms)
我的流程基本上是在這個活動如果數據庫中的特定值爲true,它會自動運行autoGO,它在autoGO中啓動一個新的intent並將我帶到該類。不過,這似乎是我開始兩個活動的地方。因此,我打開了兩個相同類型的活動,但這是不需要的。這可能是什麼原因?
這裏是autoGO方法:
public void autoGO(View arg1) throws IOException,
XmlPullParserException {
EditText username = (EditText) findViewById(R.id.widget40);
EditText password = (EditText) findViewById(R.id.widget37);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//gainString(remembered);
setUserPass();
System.out.println(Compare[1]);
System.out.println(Compare[2]);
request.addProperty("User", Compare[1]);
request.addProperty("Password", Compare[2]);
autoSign = false;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope); // send request
SoapObject result = (SoapObject) envelope.getResponse(); // get
System.out.println(result);
int Conversion = Integer.parseInt(result.getProperty(0).toString());
System.out.println(Conversion);
if (Conversion > 0) {
try{
sqlDB=openOrCreateDatabase(DBNAME1,Context.MODE_PRIVATE,null);
System.out.println("open or create database");
//sqlDB.execSQL("UPDATE " + Table1 + " SET NAME = '" + sUserName + "' WHERE NAME = '" + remembered[1] + "'");
System.out.println("URL updated");
//sqlDB.execSQL("UPDATE " + Table1 + " SET PASSWORD = '" + sPassword + "' WHERE PASSWORD = '" + remembered[2]+ "'");
sqlDB.execSQL("UPDATE " + Table1 + " SET URL = '" + "http://" + result.getProperty(2).toString()+ "'");
System.out.println("HERE IS THE NEW URL " + "http://" + result.getProperty(2).toString());
contentScreen co = new contentScreen();
co.signAuto(true);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, contentScreen.class);
startActivity(intent);
finish();
}
catch (Exception e1) {
// TODO Auto-generated catch block
System.out.println("Problem "+ e1.getMessage());
e1.printStackTrace();
}
finally
{
sqlDB.close();
}
} else {
username.setTextSize(10);
username.setText("Invalid username or passcode!");
}
}
下面是完整的代碼:
public class Activity1 extends Activity {
/** Called when the activity is first created. */
JoshTwoActivity main;
Activity1 Activity1;
Activity2 two;
boolean checkTick = false;
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://xxxxxxxxxxxxxxxxxxxxxx/Webservice/xxxxxxxxxxxe.asmx?WSDL";
private static final String SOAP_ACTION = "http://tempuri.org/ValidateUser";
private static final String METHOD_NAME = "ValidateUser";
static String[] Compare = {"First time login, please enter name","pass","http://default.com"};
boolean tickBoxes [] = {false, false};
private String[] remembered = { "", "", "", "" };
View arg3;
Boolean autoSign = false;
SQLiteDatabase sqlDB;
private static String DBNAME1= "database1.db";
private static String DBNAME2= "database2.db";
private static String Table1= "People";
private static String Table2= "options";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(1);
final EditText username = (EditText) findViewById(R.id.widget40);
final EditText password = (EditText) findViewById(R.id.widget37);
obtainDetails();
getValues();
final CheckBox checkBox = (CheckBox) findViewById(R.id.widget35);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
if (checkBox.isChecked()) {
tickBoxes[0]=true;
updateFields();
}
if (!checkBox.isChecked()) {
tickBoxes[0]=false;
updateFields();
}
}
});
// NEW SAVE CHECKBOX IS HERE
final CheckBox saveBox = (CheckBox) findViewById(R.id.widget36);
saveBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
if (saveBox.isChecked()) {
tickBoxes[1]=true;
updateFields();
}
if (!saveBox.isChecked()) {
tickBoxes[1]=false;
System.out.println(tickBoxes[1]);
updateFields();
}
}
});
// FOR LOOP TO GO HERE, AND ALSO REMOVAL OF CHECKTICK
for (int i = 0; i < tickBoxes.length; i++) {
if (tickBoxes[1]) {
saveBox.setChecked(true);
if(!tickBoxes[0]){
try {
//gainString(remembered);
setUserPass();
username.setText(remembered[1]);
System.out.println(remembered[1]);
password.setText(remembered[2]);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// SET THE TEXT HERE IF NEEDED
}
if (tickBoxes[0]) {
checkBox.setChecked(true);
try {
autoSign = true;
System.out.println(autoSign);
autoGO(arg3);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
final Button buttonEXIT = (Button) findViewById(R.id.widget41);
buttonEXIT.setOnClickListener(new ViewStub.OnClickListener() {
@Override
public void onClick(View arg3) {
username.setText("");
password.setText("");
checkBox.setChecked(false);
saveBox.setChecked(false);
updateFields();
}
});
layoutControl();
}
public void destory(boolean newterminate) {
main.sessionDestroy(newterminate);
}
public void layoutControl() {
final Button buttonLOGIN = (Button) findViewById(R.id.widget34);
buttonLOGIN.setOnClickListener(new ViewStub.OnClickListener() {
@Override
public void onClick(View arg1) {
// TODO Auto-generated method stub
try {
validateUser(arg1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
final Button signUP = (Button) findViewById(R.id.widget32);
signUP.setOnClickListener(new ViewStub.OnClickListener() {
@Override
public void onClick(View arg4) {
// TODO Auto-generated method stub
// startActivity(launchBrowser);
Intent myIntent = new Intent(arg4.getContext(), login.class);
startActivityForResult(myIntent, 0);
finish();
}
});
}
public void updateFields()
{
String one;
String two;
if(tickBoxes[0]){
one = "true";
two = "false";
}
else{
one = "false";
two = "true";
}
String three;
String four;
if(tickBoxes[1])
{
three = "true";
four = "false";
}
else
{
three = "false";
four = "true";
}
System.out.println("badadfasdfa" +one);
System.out.println("badadfasdfa" +two);
try{
sqlDB= openOrCreateDatabase(DBNAME2,Context.MODE_PRIVATE,null);
System.out.println("values updated");
sqlDB.execSQL("UPDATE " + Table2 + " SET SaveP= '" + three + "' WHERE SaveP = '" + four + "'");
sqlDB.execSQL("UPDATE " + Table2 + " SET Signauto= '" + one+ "' WHERE Signauto = '" + two+ "'");
sqlDB.close();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
sqlDB.close();
}
}
public void validateUser(View arg1) throws IOException,
XmlPullParserException {
EditText username = (EditText) findViewById(R.id.widget40);
EditText password = (EditText) findViewById(R.id.widget37);
String sUserName, sPassword;
sUserName = username.getText().toString();
sPassword = password.getText().toString();
System.out.println(sPassword + " USERJHJERJ");
if(!autoSign){
if (sUserName.length() <= 2 || sPassword.length() <= 2) {
username.setTextSize(10);
username.setText("enter both fields!");
} else {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set
request.addProperty("User", sUserName); // variable name, value. I
// got
request.addProperty("Password", sPassword);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11); // put all required data into a soap
// envelope
envelope.dotNet = true;
envelope.setOutputSoapObject(request); // prepare request
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope); // send request
System.out.println("HERE IS THE ENVELOPE "
+ envelope.getInfo("User", "Password"));
SoapObject result = (SoapObject) envelope.getResponse(); // get
System.out.println(result);
// String checkPass =
int Conversion = Integer.parseInt(result.getProperty(0).toString());
System.out.println(Conversion);
if (Conversion > 0) {
try{
sqlDB=openOrCreateDatabase(DBNAME1,Context.MODE_PRIVATE,null);
System.out.println("open or create database");
sqlDB.execSQL("UPDATE " + Table1 + " SET NAME = '" + sUserName + "' WHERE NAME = '" + Compare[1] + "'");
System.out.println("username updated");
sqlDB.execSQL("UPDATE " + Table1 + " SET PASSWORD = '" + sPassword + "' WHERE PASSWORD = '" + Compare[2]+ "'");
sqlDB.execSQL("UPDATE " + Table1 + " SET URL = '" + "http://" + result.getProperty(2).toString() + "' WHERE URL = '" + Compare[0] + "'");
Intent myIntent = new Intent(arg1.getContext(),
contentScreen.class);
startActivityForResult(myIntent, 0);
finish();
}
/*eStrings[0] = result.getProperty(0).toString();
eStrings[1] = sUserName;
eStrings[2] = sPassword;
eStrings[3] = "http://" + result.getProperty(2).toString();*/
catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println(e1.toString() + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
}
finally
{
sqlDB.close();
}
} else {
username.setTextSize(10);
username.setText("Invalid username or passcode!");
}
}}
//}else{
//}
}
public void autoGO(View arg1) throws IOException,
XmlPullParserException {
EditText username = (EditText) findViewById(R.id.widget40);
EditText password = (EditText) findViewById(R.id.widget37);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//gainString(remembered);
setUserPass();
System.out.println(Compare[1]);
System.out.println(Compare[2]);
request.addProperty("User", Compare[1]);
request.addProperty("Password", Compare[2]);
autoSign = false;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope); // send request
SoapObject result = (SoapObject) envelope.getResponse(); // get
System.out.println(result);
int Conversion = Integer.parseInt(result.getProperty(0).toString());
System.out.println(Conversion);
if (Conversion > 0) {
try{
sqlDB=openOrCreateDatabase(DBNAME1,Context.MODE_PRIVATE,null);
System.out.println("open or create database");
//sqlDB.execSQL("UPDATE " + Table1 + " SET NAME = '" + sUserName + "' WHERE NAME = '" + remembered[1] + "'");
System.out.println("URL updated");
//sqlDB.execSQL("UPDATE " + Table1 + " SET PASSWORD = '" + sPassword + "' WHERE PASSWORD = '" + remembered[2]+ "'");
sqlDB.execSQL("UPDATE " + Table1 + " SET URL = '" + "http://" + result.getProperty(2).toString()+ "'");
System.out.println("HERE IS THE NEW URL " + "http://" + result.getProperty(2).toString());
contentScreen co = new contentScreen();
co.signAuto(true);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, contentScreen.class);
startActivity(intent);
finish();
}
catch (Exception e1) {
// TODO Auto-generated catch block
System.out.println("Problem "+ e1.getMessage());
e1.printStackTrace();
}
finally
{
sqlDB.close();
}
} else {
username.setTextSize(10);
username.setText("Invalid username or passcode!");
}
}
public void getValues()
{
try{
sqlDB= this.openOrCreateDatabase(DBNAME2,MODE_PRIVATE,null);
Cursor r=sqlDB.rawQuery("SELECT Signauto,SaveP FROM "+Table2, null);
System.out.println("COUNT : " + r.getCount());
Integer sign=r.getColumnIndex("Signauto");
Integer save=r.getColumnIndex("SaveP");
int j=0;
if(r.moveToFirst()){
do
{
System.out.println("sign values are"+r.getString(sign));
System.out.println("save values are"+r.getString(save));
//int a[]=new int[tickBoxes.length];
j++;
if(r.getString(sign).equals("true"))
{
tickBoxes[0]=true;
System.out.println("values of tickbox"+tickBoxes[0]);
}
else
{
tickBoxes[0]=false;
}
if(r.getString(save).equals("true"))
{
tickBoxes[1]=true;
System.out.println("values of tickbox"+tickBoxes[1]);
}
else
{
tickBoxes[1]=false;
}
}
while(r.moveToNext());
if(j==0)
{
System.out.println("No data found");
}
}
r.close();
//sqlDB.close();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
sqlDB.close();
}
}
public String[] setUserPass()
{
try{
sqlDB= this.openOrCreateDatabase(DBNAME1,MODE_PRIVATE,null);
Cursor r=sqlDB.rawQuery("SELECT NAME, PASSWORD, URL FROM " +Table1, null);
System.out.println("COUNT : " + r.getCount());
Integer uname=r.getColumnIndex("NAME");
Integer pwd=r.getColumnIndex("PASSWORD");
Integer url=r.getColumnIndex("URL");
if(r.moveToFirst())
{
do{
remembered[1]=r.getString(uname);
System.out.println("remembered 1"+remembered[1]);
remembered[2]=r.getString(pwd);
remembered[0]=r.getString(url);
System.out.println("newnewnew " + r.getString(url));
}
while(r.moveToNext());
}
r.close();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("BBBBBBBBBBBBBBBBBBBB" + e.toString());
}
finally{
sqlDB.close();
}
return remembered;
}
public String[] obtainDetails(){
try{
sqlDB= this.openOrCreateDatabase(DBNAME1,MODE_PRIVATE,null);
Cursor r=sqlDB.rawQuery("SELECT NAME, PASSWORD, URL FROM " +Table1, null);
System.out.println("COUNT : " + r.getCount());
Integer uname=r.getColumnIndex("NAME");
Integer pwd=r.getColumnIndex("PASSWORD");
Integer url=r.getColumnIndex("URL");
if(r.moveToFirst())
{
do{
Compare[1]=r.getString(uname);
System.out.println("remembered 1"+remembered[1]);
Compare[2]=r.getString(pwd);
Compare[0]=r.getString(url);
}
while(r.moveToNext());
}
r.close();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" + e.toString());
}
finally{
sqlDB.close();
}
return Compare;
}
}
輝煌。我應該在android manifest中調用什麼特定的類?你有一個例子嗎? –
我不知道它是,我刪除它,我仍然得到首發 –
在approprite活動節點集合屬性的兩個活動**機器人:screenOrientation =「風景」 **。查看更多[這裏](http://developer.android.com/guide/topics/manifest/activity-element.html#screen) – slkorolev