Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:08:58+00:00 2026-06-18T02:08:58+00:00

My code is working fine not until the table or the device is rotated.

  • 0

My code is working fine not until the table or the device is rotated. When rotated the drawing got cleared and I learned it happen because when the device gets rotated, the activity is restarted.
My problem is how redraw and save the data to onSaveInstanceState.
Many said that I have to use onSaveInstanceState to save the drawing, but i don’t know how to do it when the datatype I have to save is the Path.

here is the snippet of my code

public class MyDrawView extends View implements OnTouchListener {
    MyDrawView drawView;
    float prevX = 0;
    float prevY = 0;

    private Bitmap mBitmap;
    private Canvas mCanvas;
    private Path mPath;
    private Paint mBitmapPaint;
    private Paint mPaint;
    private int w,h;
    private ArrayList<Path> paths = new ArrayList<Path>();
    private ArrayList<Paint> bitPaints = new ArrayList<Paint>();
    private ArrayList<Paint> pathPaints = new ArrayList<Paint>();
    Paint tempPaint;
    private String filename="";

    public MyDrawView(Context c,String filename) {
        super(c);
        mPath = new Path();
        mBitmapPaint = new Paint(Paint.DITHER_FLAG);


        this.filename=filename;
        setFocusable(true);
        setFocusableInTouchMode(true);
        this.setOnTouchListener(this);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(6);
        tempPaint=new Paint(mPaint);
        mCanvas = new Canvas();
        mPath = new Path();
        if (rotated){
            setDefaultDrawing();
        }

    }
    public void setDefaultDrawing()
    {

    }
    public Bitmap getBitmap(){
        return this.mBitmap;
    }
    public void setStrokeWidth(float width){
        mPaint.setStrokeWidth(width);
    }
    public void setColor(int color){
        mPaint.setColor(color);
    }
    public String getFileName(){
        return this.filename;
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.w=w;
        this.h=h;
        mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
        Path tempPath=new Path(mPath);
        paths.add(tempPath);
        Paint tempPaint=new Paint(mPaint);
        pathPaints.add(tempPaint);
        Paint tempBitPaint=new Paint(mBitmapPaint);
        bitPaints.add(tempBitPaint);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

        canvas.drawPath(mPath, mPaint);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:08:59+00:00Added an answer on June 18, 2026 at 2:08 am

    I figured it out, since Path is a custom object, I created a class object that will hold the Path, in that way, I can just save the class object in my onSaveInstanceState and retrieve it using the same class object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code looks fine but it is not working as it should because update
This code was working fine until i went to firefox 4 and now it
I am developing a tablet app. Everything is working fine until device is locked.
I’m trying to issue web requests asynchronously. I have my code working fine except
My code is working fine without any errors when running in Netbeans. If I
So basically this code was working fine before. I had some computer issues and
the below code is working fine if the user enters the USN number that
For single output types my code is working fine but I couldn't get how
My code was working absolutely fine before the launch of iPhone SDK 3.0 ,
So my code has been working fine, and I was added some extra functionality

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.