gpt4 book ai didi

android - 停止 Android Activity ,使用 noHistory ="true"

转载 作者:行者123 更新时间:2023-11-30 03:22:48 25 4
gpt4 key购买 nike

我已经在 Internet 上阅读了有关此主题的信息,但我还没有找到解决方案。 list 文件中的解决方案如 :noHistory="true"。我想要的是,在用户单击 AddNewItem 类中的保存按钮后,这会将用户重定向到 MainActivity 类,当用户单击后退按钮时,它将返回到 mainMenu,在我进行的每一步都不会返回制成。

这是我的 list 文件

 <activity
android:name="com.example.shoppingapp.AddNewItems"
android:label=""
android:noHistory="true">

</activity>

这是我的主要 Activity >

public class MainActivity extends ListActivity {

// The Intent is used to issue that an operation should
// be performed

Intent intent;
TextView itemId;

// The object that allows me to manipulate the database

ShoppingDB shopdatabase = new ShoppingDB(this);

// Called when the Activity is first called

protected void onCreate(Bundle savedInstanceState) {
// Get saved data if there is any

super.onCreate(savedInstanceState);

// Designate that edit_contact.xml is the interface used
// is activity_main.xml

setContentView(R.layout.activity_main);

// Gets all the data from the database and stores it
// in an ArrayList

ArrayList<HashMap<String, String>> contactList = shopdatabase.getAllItems();

// Check to make sure there are contacts to display

if(contactList.size()!=0) {

// Get the ListView and assign an event handler to it

ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

// When an item is clicked get the TextView
// with a matching checkId

itemId = (TextView) view.findViewById(R.id.itemId);

// Convert that itemId into a String

String itemIdValue = itemId.getText().toString();

// Signals an intention to do something
// getApplication() returns the application that owns
// this activity

Intent theIndent = new Intent(getApplication(),EditItemList.class);

// Put additional data in for EditContact to use

theIndent.putExtra("itemId", itemIdValue);

// Calls for EditContact

startActivity(theIndent);

}
});

// A list adapter is used bridge between a ListView and
// the ListViews data

// The SimpleAdapter connects the data in an ArrayList
// to the XML file

// First we pass in a Context to provide information needed
// about the application
// The ArrayList of data is next followed by the xml resource
// Then we have the names of the data in String format and
// their specific resource ids

ListAdapter adapter = new SimpleAdapter( MainActivity.this,contactList, R.layout.item_list_entry, new String[] { "itemId","textAmount", "textItem"}, new int[] {R.id.itemId, R.id.textAmount, R.id.textItem});

// setListAdapter provides the Cursor for the ListView
// The Cursor provides access to the database data

setListAdapter(adapter);


}

}


public void callStartApp(View view){

Intent startIntent = new Intent(getApplication(), StartingApp.class);

startActivity(startIntent);

}

// When showAddContact is called with a click the Activity
// NewContact is called

public void showAddItem(View view) {
Intent theIntent = new Intent(getApplicationContext(), AddNewItems.class);
startActivity(theIntent);
}


}

这是我的 AddNewItem 类

public class AddNewItems extends Activity {

// The EditText objects

EditText textItem;
EditText textAmount;
EditText textPrice;
EditText textPlace;

ShoppingDB shopdatabase = new ShoppingDB(this);


@Override
public void onCreate(Bundle savedInstanceState) {

// Get saved data if there is any

super.onCreate(savedInstanceState);

// Designate that add_new_item.xml is the interface used

setContentView(R.layout.add_item);

// Initialize the EditText objects

textItem = (EditText) findViewById(R.id.textItem);
textAmount = (EditText) findViewById(R.id.textAmount);
textPrice = (EditText) findViewById(R.id.textPrice);
textPlace = (EditText) findViewById(R.id.textPlace);


}
public void addNewItems(View view) {

// Will hold the HashMap of values

HashMap<String, String> queryValuesMap = new HashMap<String, String>();

// Get the values from the EditText boxes

queryValuesMap.put("textItem", textItem.getText().toString());
queryValuesMap.put("textAmount", textAmount.getText().toString());
queryValuesMap.put("textPrice", textPrice.getText().toString());
queryValuesMap.put("textPlace", textPlace.getText().toString());


// Call for the HashMap to be added to the database

shopdatabase.insertItem(queryValuesMap);

// Call for MainActivity to execute

this.callMainActivity(view);
}
public void callMainActivity(View view) {
Intent theIntent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(theIntent);
}
}

最佳答案

它重定向到 mainactivty 类-

Intent i = new Intent(this, MAinActivity.class);
finish();
startActivity(i);

对于主菜单-

Intent i = new Intent(this, abcActivity.class);
finish();

在这里,我为您的 mainmenuActivity 编写了 abcActivity。在 abcActivity 的地方写下你的 menuActivity 类名。

关于android - 停止 Android Activity ,使用 noHistory ="true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18801285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com