-2

i have a interface in FirstActivity , i want to send a value with interface to SecondAcitivty , but after implement interface in SecondActivity i get this error :

Cyclic inheritance involving 'com.example.user.classmanager.AlertDialogShowStudentScore'

FirstActivity:

public class StudentScoreActivity extends AppCompatActivity
{ 
    private updateStudentScore updateStudentScore;  

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {

    this.updateStudentScore= (updateStudentScore) this; 
    }

     public interface updateStudentScore
    {
        void updateRangeScore(float score);
    }
}

SecondActivity:

public class AlertDialogShowStudentScore implements StudentScoreActivity.updateStudentScore
{
    . . . 
}

enter image description here

Nima Khalili
  • 201
  • 1
  • 17
  • 1
    if you want to share a data then use bundle with intent. – Urvish rana Apr 08 '19 at 12:09
  • 2
    You do not use interface to pass data between Activities . Root cause is You Do not have Object of that Activity in other Activity . [Pass data with Bundle in Traditional way](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) . – ADM Apr 08 '19 at 12:10
  • Instead of using the interface to communicate between activities use *#startActivityForResult(android.content.Intent, int)* – Muthukrishnan Rajendran Apr 08 '19 at 12:11
  • My question was wrong , I don't want to go second activity , I just want to update a variable in second activity. – Nima Khalili Apr 08 '19 at 12:18
  • Note: Names of classes and Interfaces should start with an Uppercase letter. – NormR Apr 08 '19 at 12:27

1 Answers1

1

you should create a data class pass first activity context to data class as listner
update data class from second activity and update data class listner(first activity) variable