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

What is the difference between onPause() and onStop() of Android Activites?

No, if some activity comes into foreground, that doesn’t necessarily mean that the other activity is completely invisible. Consider the following case: Here we see both activities at the same time. The first activity with the fields is obscured by another activity, and the user can no longer interact with it. However, it is still … Read more

How do I prevent Android taking a screenshot when my app goes to the background?

Try FLAG_SECURE: public class FlagSecureTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); setContentView(R.layout.main); } } This definitely secures against manual screenshots and automatic screenshots from the ICS recent-tasks history. It also secures against screen recording (e.g., apps using the media projection APIs). UPDATE: it also secures against Now On Tap … Read more

java.lang.IllegalStateException: Fragment not attached to Activity

This error happens due to the combined effect of two factors: The HTTP request, when complete, invokes either onResponse() or onError() (which work on the main thread) without knowing whether the Activity is still in the foreground or not. If the Activity is gone (the user navigated elsewhere), getActivity() returns null. The Volley Response is … Read more

App restarts rather than resumes

The behavior you are experiencing is caused by an issue that exists in some Android launchers since API 1. You can find details about the bug as well as possible solutions here: https://code.google.com/p/android/issues/detail?id=2373. It’s a relatively common issue on Samsung devices as well as other manufacturers that use a custom launcher/skin. I haven’t seen the … Read more

On logout, clear Activity history stack, preventing “back” button from opening logged-in-only Activities

I can suggest you another approach IMHO more robust. Basically you need to broadcast a logout message to all your Activities needing to stay under a logged-in status. So you can use the sendBroadcast and install a BroadcastReceiver in all your Actvities. Something like this: /** on your logout method:**/ Intent broadcastIntent = new Intent(); … Read more

Difference and uses of onCreate(), onCreateView() and onActivityCreated() in fragments

UPDATE: onActivityCreated() is deprecated from API Level 28. onCreate(): The onCreate() method in a Fragment is called after the Activity‘s onAttachFragment() but before that Fragment‘s onCreateView(). In this method, you can assign variables, get Intent extras, and anything else that doesn’t involve the View hierarchy (i.e. non-graphical initialisations). This is because this method can be … Read more

How to start new activity on button click

Easy. Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); myIntent.putExtra(“key”, value); //Optional parameters CurrentActivity.this.startActivity(myIntent); Extras are retrieved on the other side via: @Override protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); String value = intent.getStringExtra(“key”); //if it’s a string you stored. } Don’t forget to add your new activity in the AndroidManifest.xml: <activity android:label=”@string/app_name” android:name=”NextActivity”/>

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