我的申请中有很多活动
因为我已经给出了
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
从其他活动返回首页
像下面
如果我按这三个按钮,所有菜单都可以使用
这是我的选项菜单
@Override
public boolean onOptionsItemSelected(MenuItem item){
int id = item.getItemId();
if (id == R.id.abc) {
Intent mypIntent = new Intent(this, abc.class);
startActivity(mypIntent);
return true;
}
else if (id == R.id.web) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
.
.
.
..
return super.onOptionsItemSelected(item);
}
此处没有名为
id == R.id.login
或id == R.id.home
的菜单,但是要登录几天才能返回首页活动但是,如果我按Back ..,返回的操作将重定向到“登录”主页
我已经使用共享首选项为我的应用程序添加了一个登录页面..现在它是启动器活动。
在“我的登录”活动中,一旦用户登录,它应该每次都重定向到“主页”活动。
和它的工作正常。
但是在操作栏上,当我按箭头按钮时,它正在重定向到空的登录页面。
如果我按“取消”,则整个应用程序都在运行..除此操作栏外,我的凭据是安全的。
更新资料
如果登录凭据成功重定向到应用程序启动时的“主页”活动,我也会给出“给定意图”,它将每次检查一次
除了采取行动外,一切都很好
如何解决这个问题...
最佳答案
好的,请确保您确实声明了以下活动-
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- The meta-data element is needed for versions lower than 4.1 -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
现在在每个活动中添加以下代码块-
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
更新资料
添加一个新的类文件以检查登录名或不使用home作为默认值..并将您的新类替换为
launcher