please i need help. I am using Navigation Drawer (Material Design) and with the picture in a circle. Now this is in an Activity and of course a have fragments. I want this picture to be in the Home fragment, that means that when the App starts the picture has to appear and when i open the menu it has to appear in the circle too. The problem is when i enter the app (username and password) it sends me an error and of course because the url image from the menu is sending null to the fragment. Now i am following the next sequence : OnCreate(activity) -> onStart(activity)->onCreateView(Fragment) ->onStart(fragment). On create Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);
Log.d("Ejecutando", "Activity3");
}
onStart Activity:
@Override
protected void onStart() {
Log.d("Ejecutando", "onStartActivity()");
AlumnoSpinner = (Spinner)findViewById(R.id.spinner);
pref = PreferenceManager.getDefaultSharedPreferences(this);
String usuario = pref .getString("usuario", "null");
String password = pref .getString("password", "null");
params.put("username", usuario );
params.put("password", password);
ShowAlumnosSpinner(URL_alumnos, params);
.....
AlumnoSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int i;
Set set = alumnosCopy.entrySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
for (i = 0; i < alumnosCopy.size(); i++) {
if (parent.getItemAtPosition(position).equals(entry.getValue().toString())) {
Toast.makeText(getApplicationContext(), "Selecciono" + entry.getValue().toString(), Toast.LENGTH_SHORT).show();
key = entry.getKey().toString();
editor = pref.edit();
editor.putString("alumnocodi", key);
editor.commit();
if (!nomCol.equals("")) {
imageUrl =//here i send the Url where i need the key, the object selected in the spinner
editor = pref.edit();
editor.putString("urlfotos", imageUrl + ".jpg");
editor.commit();
} else {
}
}
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
..............
}
onCreateView fragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
Log.d("Ejecutando", "onCreateView()");
if (!isMyServiceRunning(BackgroundService.class)) {
alarmMgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
Intent alarm = new Intent(getActivity(), AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, alarm, 0);
// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 6);
calendar.set(Calendar.MINUTE, 30);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 1, pendingIntent);
}
return rootView;
}
onStart fragment:
@Override
public void onStart() {
pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
String url = pref.getString("urlfotos", "null");
Log.d("Ejecutando", "onStart()");
new downloadImage().execute(url); // is a function that send the picture to an ImageView
super.onStart();
}
if someone please help me to figure out how can i send the URL or the bitmap to the fragment because that's what i have until now, its not working. Thanks :)