2012-08-15 56 views
0

我正在開發一個應用程序,我想知道當用戶從不是onCreate()的方法啓動我的應用程序時,用戶有多大的音量。我已經創建了一個基於我的onCreate內的當前卷的int,但因爲它不能返回任何東西,我不知道如何從那裏獲取我的int。使用onCreate()中生成的int I非常重要。創建返回在應用程序啓動時獲得的值的方法

這怎麼辦?

+1

後,你已經完成了代碼

寫入喜好

SharedPreferences pref = context.getSharedPreferences("MyAppPreferences", Context.MODE_PRIVATE); /* * Get the editor for this object. The editor interface abstracts the implementation of * updating the SharedPreferences object. */ SharedPreferences.Editor editor = pref.edit(); /* * Write the keys and values to the Editor */ editor.putInt("VolumLevel", 60); /* * Commit the changes. Return the result of the commit. */ e.commit(); 

READ。它會給這個問題提供背景 – nandeesh 2012-08-15 17:47:08

回答

0

@pawegio權利,如果你想使用相同的音量水平用戶設置,使用偏好。 這是如何從喜好

SharedPreferences pref = context.getSharedPreferences("MyAppPreferences", MODE_PRIVATE); 
int volLevel = pref.getInt("VolumLevel", 50 /*Default if value wasn't setup yet*/); 

return volLevel; 
相關問題