Android: Clear Activity Stack

Most of you are wrong. If you want to close existing activity stack regardless of what’s in there and create new root, correct set of flags is the following: intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); From the doc: public static final int FLAG_ACTIVITY_CLEAR_TASK Added in API level 11 If set in an Intent passed to Context.startActivity(), this flag … Read more

Shared preferences for creating one time activity

Setting values in Preference: // MY_PREFS_NAME – a static String variable like: //public static final String MY_PREFS_NAME = “MyPrefsFile”; SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); editor.putString(“name”, “Elena”); editor.putInt(“idName”, 12); editor.apply(); Retrieve data from preference: SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); String name = prefs.getString(“name”, “No name defined”);//”No name defined” is the default value. int idName = prefs.getInt(“idName”, … Read more

runOnUiThread in fragment

Try this: getActivity().runOnUiThread(new Runnable… It’s because: 1) the implicit this in your call to runOnUiThread is referring to AsyncTask, not your fragment. 2) Fragment doesn’t have runOnUiThread. However, Activity does. Note that Activity just executes the Runnable if you’re already on the main thread, otherwise it uses a Handler. You can implement a Handler in … Read more

How to pass a variable from Activity to Fragment, and pass it back?

To pass info to a fragment , you setArguments when you create it, and you can retrieve this argument later on the method onCreate or onCreateView of your fragment. On the newInstance function of your fragment you add the arguments you wanna send to it: /** * Create a new instance of DetailsFragment, initialized to … Read more

Android: how to make an activity return results to the activity which calls it?

In order to start an activity which should return result to the calling activity, you should do something like below. You should pass the requestcode as shown below in order to identify that you got the result from the activity you started. startActivityForResult(new Intent(“YourFullyQualifiedClassName”),requestCode); In the activity you can make use of setData() to return … Read more

One Activity and all other Fragments [closed]

It depends on the app you are creating. I’ve created several apps using both approaches and can’t say one way is always better than the other. The latest app I created I used the single Activity approach and a Facebook style navigation. When selecting items from the navigation list I update a single Fragment container … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)