• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • 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
 
Tim Moores
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic