• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is needed to handle the navigation drawer during an orientation change?

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

My requirement is very simple I am using a navigation drawer in my app and I want to display different layout for same selected value on landscape and portrait orientation so far I think I need to handle these things

*Async Tasks
*Data in App

so what other things are needed to handle properly I am following Single activity and multiple fragments paradigm of navigation drawer
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what the navigation drawer has to do with orientation changes. If you're asking about mitigating the impact of an app restart, have you considered NOT to have that happen by way of setting android:configChanges="orientation" in the manifest?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my requirement is I want to show two different layout of same selected item from navigation drawer for both in landscape and portrait mode.And I also want to preserve network state and data download in one section.

How can I meet these changes
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And I also want to preserve network state and data download in one section.


That's most easily done by NOT having your app respond automatically to orientation changes, via the mechanism I mentioned in my previous post.

I want to show two different layout of same selected item from navigation drawer for both in landscape and portrait mode.


If the app does not respond to orientation changes with a restart, then you would do this programmatically in the onConfigurationChanged handler, possibly by setting a different adapter with a different layout for the drawer ListView.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That's most easily done by NOT having your app respond automatically to orientation changes, via the mechanism I mentioned in my previous post.



so where will be async task run in my case in main activity because I will replace fragment when orientation of device changes what I need to call something like setRetainInstance() and in onCreate() get
that instance object from fragment in activity and pass that object to another fragment of same selection item in navigation drawer.Is that what you are suggesting

 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think you need to do anything with respect to background processing or fragments when the orientation changes? If you proceed as I suggested, onCreate wouldn't even be called, because the activity continues to run uninterrupted. The GUI elements will be rotated by Android without your code needing to do anything.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But as per this document on android developer site
https://developer.android.com/guide/topics/resources/runtime-changes.html


Handling the configuration change yourself can make it much more difficult to use alternative resources, because the system does not automatically apply them for you. This technique should be considered a last resort when you must avoid restarts due to a configuration change and is not recommended for most applications.



so I also want different layout in both mode(portrait and landscape).

let me explain my use case

I am designing an application which has a blogs Option in navigation drawer.So whethar the device is in landscpae or Portrait or user switch between these two modes ,data that is downloading from server using async task
should be countinue download.and once download is complete it should update blogs layout whethar it is in landscpae or portrait


So what solution I should use
1)Retain an Object during Configuration Change
2)Handling Configuration Changes yourself
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's just the download you're worrying about, start by finding out whether you can use Android's built-in DownloadManager for that. If you can, the problem would go away.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to use DownloadManager I will use AsyncTask to get JSON Data and then Parse It.
I want to preserve that Download not Android's built in DownloadManager
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I don't want to use DownloadManager.


Why not? After the download you can store the data wherever you like. (If that's what you mean by "preserve" - I'm not sure.)
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Just a question I have a URL and that will reply JSON data which contain both Bitmaps and Plain Text

I want to countinue download that data and not lost when device change orientation .which one I should use

1)Async Task

2)Download Manager

(If possible please explain why is one is better than other)
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given that you specifically want to handle orientation changes, the preference should be DownloadManager, as it avoids the problem. That assumes you can use it to get at you data, obviously - you haven't said whether you have checked that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic