[英]android simulator crashes when using intent
我是android studio的新手,正在使用Java編寫應用程序。 我發現,當我使用意向做從頁面調用頁面跳轉PhotosActivity
到另一個頁面調用AndroidTabLayoutActivity
是失敗了,我有什么事情on.The的Android模擬器不知道簡化版,給我任何錯誤的按摩,它只是關閉應用程序自動。
調用意圖的代碼:
if (!error) {
Toast.makeText(getApplicationContext(), "Offer successfully inserted.", Toast.LENGTH_LONG).show();
// Jump to the AndroidTabLayoutActivity page
Intent intent = new Intent(
PhotosActivity.this,
AndroidTabLayoutActivity.class);
startActivity(intent);
finish();
}
AndroidTabLayoutActivity的代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Photos
TabSpec photospec = tabHost.newTabSpec("Photos");
photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
photospec.setContent(photosIntent);
//there is still some others tab in here
// Adding all TabSpec to TabHost
tabHost.addTab(photospec); // Adding photos tab
}
You have using getApplicationContext() in this toast method
Replace with activity context, i am sure your code is working fine
Toast.makeText(getApplicationContext(), "Offer successfully inserted.",
Toast.LENGTH_LONG).show();
Use like this
Toast.makeText(PhotosActivity.this, "Offer successfully inserted.",
Toast.LENGTH_LONG).show();
由於沒有任何特定的錯誤日志。 我們必須回溯所有可能性。
首先,用這個代替你的吐司。
Toast.makeText(getApplicationContext(), "Offer successfully inserted.", Toast.LENGTH_LONG).show();
之后,請確保已在AndroidManifest.xml
文件中聲明了AndroidTabLayoutActivity
在您的AndroidTabLayoutActivity
Cooment了所有的代碼,並檢查其工作? 如果是,則AndroidTabLayoutActivity
問題。 用適合您的方式回復我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.