0

I am developing a lockscreen and i want to swipe between two activities like we swipe the home screen. I searched everywhere but i did not find any perfect answer. I used the view pager but its not working on activities. Then i tried this:

public void change(){
    int1= new Intent(this,WheelActivity.class);
    startActivityForResult(int1,1000);
      overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
    finish();
}
public void change1(){

    int1= new Intent(this,ImageActivity.class);
    startActivityForResult(int1,1000);
      overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    finish();
}

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);

    }

 @Override
    public boolean onTouchEvent(MotionEvent me) {
        return gDetector.onTouchEvent(me);
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent start, MotionEvent finish, float xVelocity, float yVelocity) {
        if (start.getRawX() < finish.getRawX()) {
            change();
        } 
        if (start.getRawX() > finish.getRawX()) {
            change1();
        } 

        return true;
    }

    @Override
    public void onLongPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
            float arg3) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

But the problem is that its not so smooth like home screen swipe or any other lockscreen. Please help me out of this problem. Thanks in advance.

Rajiv
  • 1
  • 1
  • Why are you using Activities for this? ViewPagers are built on views or fragments. – ianhanniballake Nov 27 '14 at 05:00
  • hey i think you should have look at this [link](http://stackoverflow.com/questions/17903105/android-how-to-add-swipe-gesture-on-linearlayout-without-ondown-true) in this just look at first answer and see that how he implemented gesture. – Aiyaz Parmar Nov 27 '14 at 05:01
  • 1
    I don't think switching activities is ever going to be as smooth as you want it to be. The Android home screen is a single activity with a really big view that contains smaller views for each of your separate screens (I know because I used to work on one). The ViewPager is smooth because it is also just moving views around within a single view hierarchy. Different activities, however, each have their own view hierarchy, and so it cannot be as smooth to swipe between them. – Bruce Nov 27 '14 at 05:02
  • because i have two activities to swipe not page @ianhanniballake – Rajiv Nov 27 '14 at 05:05
  • ViewPager keep a snapshort of the activity not the real one and I have the activity which contain the time and when i use viewpager the time doesn't change. So if there is any other way to solve this problem then please suggest me @Bruce – Rajiv Nov 27 '14 at 05:09
  • None that I know. What is keeping you from using fragments? – Bruce Nov 27 '14 at 07:51
  • Yeah I am trying the fragment..but fragment is supporting only higher version than honeycomb. @Bruce – Rajiv Dec 02 '14 at 15:45
  • Use the support libraries -- they are well worth the trouble. They allow you to use the latest features while maintaining compatibility. Since you are not yet using fragments, the main transition would be subclassing FragmentActivity instead of Activity. Then make sure you always use the support version of fragment-related classes, and that you call getSupportFragmentManager in your activities. – Bruce Dec 02 '14 at 16:45
  • Do you have any examples which helps me to go towards my project..I am still there and i can't get out from this situation. Actually i do have two activities and these two activities already contain lot of java code and XML file (specific to my project). So now tell me how could I swipe between these two activities. Please help me I really need your help..Thanks for your appreciation. :) -Bruce – Rajiv Dec 11 '14 at 15:50

0 Answers0