Display fragment viewpager within a fragment

use AsyncTask to set the adapter for viewPager. It works for me. The asyncTask is to make the original fragment complete it’s transition. and then we proceed with viewPager fragments, basically to avoid recursion. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.team_card_master, container, false); mViewPager = (ViewPager)mView.findViewById(R.id.team_card_master_view_pager); final Button button … Read more

How to know when my app has been killed?

I have found one way to do this….. Make one service like this public class OnClearFromRecentService extends Service { @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(“ClearFromRecentService”, “Service Started”); return START_NOT_STICKY; } @Override public void onDestroy() { super.onDestroy(); Log.d(“ClearFromRecentService”, “Service Destroyed”); } @Override … Read more

Why use Fragment#setRetainInstance(boolean)?

How do you as a developer use this Call setRetainInstance(true). I typically do that in onCreateView() or onActivityCreated(), where I use it. and why does it make things easier? It tends to be simpler than onRetainNonConfigurationInstance() for handling the retention of data across configuration changes (e.g., rotating the device from portrait to landscape). Non-retained fragments … 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

When Can I First Measure a View?

I didn’t know about ViewTreeObserver.addOnPreDrawListener(), and I tried it in a test project. With your code it would look like this: public void onCreate() { setContentView(R.layout.main); final TextView tv = (TextView)findViewById(R.id.image_test); final LayerDrawable ld = (LayerDrawable)tv.getBackground(); final ViewTreeObserver obs = tv.getViewTreeObserver(); obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw () { Log.d(TAG, “onPreDraw tv height is … 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 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