android


onCreateView is called after returning back from second activity


I have MainActivityFragment from where I start DetailActivity with below code:
private final CurrencyListAdapter.ClickListener itemClickListener
= new CurrencyListAdapter.ClickListener() {
#Override
public void onItemClick(int position, View v) {
Intent intent = new Intent(getActivity(), DetailActivity.class);
String code = mCurrencyList.get(position).getCode();
intent.putExtra(Constants.SELECTED_CODE_KEY, code);
startActivity(intent);
}
};
After that from my DetailActivity I start my DetailActivityFragment with below code:
if (savedInstanceState == null) {
DetailActivityFragment fragment = DetailActivityFragment.getInstance(code);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.detail_container, fragment)
.commit();
}
Also I am retaining the instance state within my MainActivityFragment. However, while hitting back button from DetailActivityFragment, onCreateView method of my MainActivityFragment is called and I am not able to restore instance state, because saveInstanceState method is not executed and thus the savedInstanceState is null.
I am very curious why this happening. This is not happening in other project wich has the same logic. I will be very thankful if anyone could help me.
I have already figured it out. I was loading MainActivity through xml layout file. I changed this and included the following code into my MainActivity and after the issue is gone:
if (savedInstanceState == null) {
MainActivityFragment fragment = new MainActivityFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_container, fragment)
.commit();
}

Related Links

How to validate an entered URL in android studio and if its not valid show the alert in pop up
Using seekbars to change RGB values android studio
How do you use a URL string to update an ImageView?
Adding OnClick listener to the view in android
How to display icon of songs in media player similar to you tube in android studio [closed]
Android startactivityforresult not called after permissionrequest
Video not play on mobile
Has Firebase a library for download videos that are on Firebase Storage?
intent share facebook - Android
how to use onPageCommitVisible under api 23 in Android
version Name Suffix
Set animation when change position viewpager with animation
How to set the notification just send once every year?
Android launch application with custom credentials
Android : library that download many sort of files
Leakcanary -can removing weak references helps to avoid memory leaks

Categories

HOME
algorithm
django
gridview
cobalt
paraview
developer-tools
string
dns
apache-jena
webdriver
jax-rs
datastore
socket.io
r-googlesheets
bitbucket-api
tivoli
web-hosting
spring-session
data-visualization
frontend
vert.x
elasticsearch-5
bing-maps
mel
startup
magnetic-cards
firefox-addon
forgot-password
identity-management
selinux
guzzle
springfox
highstock
outliers
soot
gp
xbox
python-2.6
fstream
processwire
video-capture
hivemq
openproject
nohup
apns-php
p4merge
doc
android-ibeacon
ssrs-2014
tcc
facebook-pixel
tinkerpop
boxing
jtree
vibrate
ampps
swingworker
redbeard-ios
android-dateutils
avspeechsynthesizer
shopping
google-query-language
kendo-upload
qt5.2
vigenere
ons-api
poppler
eoferror
viola-jones
baasbox
liquid-layout
mirror
typeconverter
mass-assignment
nodelist
showdialog
deform
post-commit-hook
ignite-ui
kissfft
mutual-authentication
file-not-found
accesscontrolexception
nevron
http-status-code-410
wimax
joomla3.1
android-loadermanager
fragmenttransaction
veracity
inline-formset
pagemethods
build-environment
purepdf
cuda.net
sqlobject

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App