从MainActivity,我开始使用intent启动ChildActivity(扩展AppCompatActivity)。 子活动的目的只是显示一些片段(欢迎文本然后用户可以填写一些编辑文本来输入他的信息)。
Intent myIntent = new Intent(this, CreateUserActivity.class);
startActivityForResult(myIntent, MainActivity.REQUEST_CREATE_PROFILE);
几秒钟后,在活动中重新启动...重新加载视图。
所以这很烦人,因为如果我在第二个片段。活动重新开始,我回到第一个。 所以我的用户必须重新开始他的工作。
重新创建活动时,我在logcat中收到以下消息:
08-07 20:45:37.673 8010-8010/com.xxxxx.xxxxxI/AppCompatViewInflater﹕ app:theme is now deprecated. Please move to using android:theme instead.
有什么想法吗?
ChildActivity代码(相关部分):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
setContentView(R.layout.activity_main); // Load the layout
createToolbar();
setUpProfile();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed(){
//super.onBackPressed();
this.moveTaskToBack(true);
}
private boolean createToolbar() {
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setNavigationIcon(R.drawable.ic_drawer_white); //TODO : It isn't taking into account...default icon is not replaced - TODO : understand why ???
mToolbar.setTitle("xxxxxx Toolbar");
mToolbar.setLogo(R.drawable.ic_menubar_v3);
mToolbar.setLogoDescription(getResources().getString(R.string.description));
mToolbar.setNavigationContentDescription(getResources().getString(R.string.navigation_icon_description));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(null);
return true;
}
//If first time app is used, then user needs to create is profile process
private boolean setUpProfile() {
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); //Disable Orientation changes
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); //Disable Drawer
WelcomeFragment myWelcomeFragment = WelcomeFragment.newInstance();
disableEnableControls(false, (ViewGroup) findViewById(R.id.root_linear_layout));
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container3, myWelcomeFragment).commit();
return true;
答案 0 :(得分:0)
我也遇到过这个问题,我发现这是因为你正在使用的自定义支持工具栏。如果没有必要,请尝试坚持传统的溢出菜单