I'm working on a very simple application that contains two activities - MainActivity (parent) and detailActivity (child). The parent and child relation is set in the manifest file.
Mainactivity has a recyclerView and for every item click in the recycler view, it open up the detailActivity.
Everything works so far except that my app runs slow.
I have a processJson method in the MainActivity's onCreate method that loads the data from a static json file. This file is pretty big( >700 rows)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_char);
processJson();
.......
}
Switching from MainActivity to DetailActivity
Intent intent = new Intent(this, CharDetailActivity.class);
intent.putExtra("charId", charId);
cxt.startActivity(intent);
Switching from DetailActivity to MainActivity is just through the backbutton or through the actionbar back button.
AndroidManifest.xml
<activity
android:name=".CharDetailActivity"
android:label="@string/title_activity_char_detail" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CharActivity" />
</activity>
If I remove the meta-tags the app calls MainActivity's oncreate only once!
Everytime the app switches from DetailActivity to MainActivity, it calls onCreate and reloads the data. Is there a better way of loading data in the app ? or save instace of the MainActivity ?