Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of NavUtils when not using the Android support library?

This question has also been asked by someone on the Android Developers Google Group (link), but it does not have an answer...

I recently removed the v4 support library from my Android project in Eclipse, because my application only targets Android 4.0 (Ice Cream Sandwich) and up. I'm now going through all the support library references that are giving me errors.

One in particular is NavUtils, which seems to be a support library class used in Activity navigation. Example:

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

What is the equivalent of NavUtils when not using the support library?

like image 808
XåpplI'-I0llwlg'I - Avatar asked Dec 18 '12 06:12

XåpplI'-I0llwlg'I -


2 Answers

Look at the source code of NavUtils, if necessary just copy it to your project. It just gets the parent activity set in the manifest and starts it.

like image 54
Nikolay Elenkov Avatar answered Nov 15 '22 12:11

Nikolay Elenkov


I found @Nikolay's approach to be the best if you don't want to have the whole android v4 support library in your project.

This is the list of classes you should copy into your project:

  • NavUtils
  • NavUtilsJB
  • IntentCompat
  • IntentCompatHoneycomb
  • IntentCompatIcsMr1
like image 35
Christian García Avatar answered Nov 15 '22 12:11

Christian García