Re: [android-developers] Changing between Navigation Drawer fragments is slow

2016-06-03 Thread TreKing
On Wed, Jun 1, 2016 at 7:20 AM, Amitai Rosenberg 
wrote:

> Is there any way I can speed up the loading of the fragments? (Perhaps
> initializing them beforehand, if this is possible?)


Looks like you're using C# which is going to limit the help you can get on
this forum.
Generally speaking, you need to use whatever tool you're using to profile
your application and determine where the bottleneck(s) is/are. Then
optimize whatever is taking the longest, rinse, and repeat.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CANCScgisMvWWRfrCQ%3DCOgz_pqruht7g-6Nqn%2By5_cSaeE4SUrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] Changing between Navigation Drawer fragments is slow

2016-06-02 Thread Amitai Rosenberg
Any ideas? 

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/4573c0f8-1653-4a1f-b5da-f4664c5335a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[android-developers] Changing between Navigation Drawer fragments is slow

2016-06-01 Thread Amitai Rosenberg


I have an app with a Navigation Drawer that uses fragments for each menu 
item.
Each time an item is clicked, I replace the current fragment.

The problem is that it takes a long time to show the new fragment after the 
user clicked.
The fragment that takes the longest to load is a fragment that has also 
tabs inside it with child fragments.
Is there any way I can speed up the loading of the fragments? (Perhaps 
initializing them beforehand, if this is possible?)


Here is my code:


protected override void OnCreate(Bundle bundle)
{
drawerLayout = FindViewById(Resource.Id.drawer_layout);
navigationView = FindViewById(Resource.Id.nav_view);
drawerLayout.DrawerClosed += DrawerLayout_DrawerClosed;
var mainFab = FindViewById(Resource.Id.mainFab);
mainFab.Click += MainFab_Click;

var callFab = FindViewById(Resource.Id.callFab);
callFab.Click += CallFab_Click;
var messageFab = 
FindViewById(Resource.Id.messageFab);
messageFab.Click += MessageFab_Click;
// Initialize the ViewPager and set an adapter
//var pager = FindViewById(Resource.Id.pager);
//pager.Adapter = new TabsFragmentPagerAdapter(SupportFragmentManager, 
fragments, titles);

// Bind the tabs to the ViewPager
//var tabs = FindViewById(Resource.Id.tabs);
//tabs.SetViewPager(pager);

navigationView.NavigationItemSelected += (sender, e) =>
{
e.MenuItem.SetChecked(true);
//react to click here and swap fragments or navigate

switch (e.MenuItem.ItemId)
{
case (Resource.Id.nav_home):
ListItemClicked(0);
break;

case (Resource.Id.nav_halachot):
ListItemClicked(1);
break;

case (Resource.Id.nav_times):
ListItemClicked(2);
break;

case (Resource.Id.nav_siddur):
ListItemClicked(3);
break;
case (Resource.Id.nav_compass):
ListItemClicked(4);
break;

case (Resource.Id.nav_settings):
ListItemClicked(5);
break;
}


drawerLayout.CloseDrawers();
};

if (bundle == null)
{
ListItemClicked(0);
navigationView.Menu.GetItem(0).SetChecked(true);
fragment = new HomeFragment();
SupportFragmentManager.BeginTransaction()
.Replace(Resource.Id.content_frame, fragment)
.Commit();
}
}

 public override void OnBackPressed()
{

if (drawerLayout.IsDrawerOpen((int)GravityFlags.Start))
{
drawerLayout.CloseDrawer((int)GravityFlags.Start);
}
else
{
base.OnBackPressed();
}
}

private void ListItemClicked(int position)
{

switch (position)
{
case 0:
fragment = new HomeFragment();
Title = "Home";
SupportActionBar.Elevation = 8;
break;
case 1:
fragment = new HalachaFragment();
Title = "aaa";
SupportActionBar.Elevation = 0;
break;
case 2:
fragment = new TimesFragment();
Title = "bbb";
SupportActionBar.Elevation = 8;

break;
case 3:
fragment = new SiddurFragment();
Title = "ccc";
SupportActionBar.Elevation = 8;
break;
case 4:
fragment = new CompassFragment();
Title = "ddd";
SupportActionBar.Elevation = 8;
break;
case 5:
fragment = new SettingsFragment();
Title = "eee";
break;
}



}

private void DrawerLayout_DrawerClosed(object sender, 
DrawerLayout.DrawerClosedEventArgs e)
{
SupportFragmentManager.BeginTransaction()
.Replace(Resource.Id.content_frame, fragment).AddToBackStack("BACK")
.Commit();

}


HalachaFragment.cs (The fragment that contains the tabs):


public class HalachaFragment : Fragment{
private ViewPager halachotPager;
private PagerSlidingTabStrip tabs;

public HalachaFragment()
{
this.RetainInstance = true;
}
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Create your fragment here
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup 
container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment

var view =