Problem is a bit complex ,First of all both activity A and activity B activity B have android:noHistory = true
in manifest. i have a custom serializable class suppose MyClass , that custom class is actually storing the context of the Activity B through constructor. And i have an object name obj in Activity B of type MyClass , Now i want to transfer this object to Activity C through intent when back button is pressed in Activity B.
From Activity A there is a button that open activity B without an issue, issue starts when i try to open activity C through B in onBackPressed(), with transferring serializable object . i am receiving NULL in Activity C.
[Updated] MyClass:
@SuppressWarnings("serial")
public class MyClass implements Serializable{
private final String SHAREDKEY_HIGHSCORE = "High Scores";
private final String FIELDKEY_HIGHSCORE = "HighScore";
private final String FIELDKEY_HIGHTIME = "HighTime";
private SharedPreferences sp;
private SharedPreferences.Editor spEditor;
public MyClass(Context context) {
resetScore();
sp = context.getSharedPreferences(SHAREDKEY_HIGHSCORE, Context.MODE_PRIVATE);
spEditor = sp.edit();
}
public void resetScore(){
newTime = 0;
newScore = 0;
highTime = 0;
highScore = 0;
}
}
Activity B:
public class ActivityB extends Activity {
MyClass scores;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
scores = new MyClass(this);
}
@Override
public void onBackPressed() {
Intent intent = new Intent(this, ActivityC.class);
in.putExtra("Scores", scores);
startActivity(intent);
}
}
Activity C:
public class ActivityC extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c);
MyClass score = (MyClass) getIntent().getSerializableExtra("Scores");
//score is null here always
}
}
Manifest:
<activity
android:name=".ActivityA"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityB"
android:noHistory="true">
</activity>
<activity android:name=".ActivityC">
How can receive my custom class in activity C successfully ? please help