How to reference an object from one Activity to another?

0

Good evening, I'm developing a multi-button app, where you can drag a button and drop it to a certain place already defined in the application, and each button has to open another screen with a different animated image (GIF) that you have with the drag button, how to set the image for each button? And what do you call it? Below is the piece of code I'm having trouble with.

View.OnLongClickListener longClickListener = new View.OnLongClickListener () {

    public boolean onLongClick(View v) {
        ClipData data = ClipData.newPlainText("","");
        View.DragShadowBuilder myShadowBuilder = new View.DragShadowBuilder(v);
        v.startDrag(data, myShadowBuilder, v, 0);
        return true;
    }
};
    View.OnDragListener dragListener = new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {

            int dragEvent = event.getAction();

            switch (dragEvent){
                case DragEvent.ACTION_DRAG_ENTERED:
                    break;

                case DragEvent.ACTION_DRAG_EXITED:
                    break;

                case DragEvent.ACTION_DROP:
                    final View view = (View) event.getLocalState();

                    if(view.getId() == R.id.btA){
                        Intent TelaBoca = new Intent(TelaAprendizagem.this, TelaFala.class);
                        startActivity(TelaBoca);
                    }
                    break;
            }
            return true;
        }
    };
    
asked by anonymous 27.07.2017 / 03:07

1 answer

0

What you can do is, in this code snippet

if(view.getId() == R.id.btA){
    Intent TelaBoca = new Intent(TelaAprendizagem.this, TelaFala.class);

    //Trecho incluido-------------------------------------------------
    TelaBoca.putExtra("viewId", view.getId());
    //----------------------------------------------------------------

    startActivity(TelaBoca);
}

Send the id of the view as an Extra in the intent, through the putExtra () of the intent.

Then in the other activity, you would get Intent from it and check if it has an Id listed, and it would show the corresponding image.

    
27.07.2017 / 13:51