1

Hey guys right now I'm not developing an app but just for learning purpose I wanted to ask that can we move the imagview from position A to B in a given time? If the time is 07:00am in the phone then the imageview should start moving and reach position B when the time is 10:00am for example. I think it is possible. But how can we achieve this? By using handler or timer?

Ajinkya More
  • 425
  • 1
  • 3
  • 15

2 Answers2

1

How about use view animation and set duration in 3hour?

sungsueya
  • 33
  • 1
  • 7
  • Will it work same way? I was thinking about it too...Can you show me an example? Like playing the animation for 3 hours and after that set `imageview` visibility to invisible? – Ajinkya More May 05 '15 at 16:58
  • 1
    there's many example in stackoverflow. http://stackoverflow.com/questions/19765938/show-and-hide-a-view-with-a-slide-up-down-animation the problem is application state, if app going to background or terminate.. – sungsueya May 05 '15 at 17:10
  • And the hardest point is I think to run it with system time. Asked this question twice but I'm not getting the accurate answer, please help me guys! – Ajinkya More May 05 '15 at 17:11
  • 1
    your should know system time by broadcast , android broadcast time change. see this http://stackoverflow.com/questions/15544996/is-there-a-way-to-detect-when-the-user-has-changed-the-clock-time-on-their-devic you also implement broadcast receiver and receive broadcast each minute then change view position. – sungsueya May 05 '15 at 17:16
  • Oh I hope now this will be possible by using `BroadcastReceiver`! By combining all knowledge at this post can you show me an example project? I'm a little newbie to this! I WOULD BE VERY THANKFUL! Please can you show sample project? – Ajinkya More May 05 '15 at 17:19
1

I think you should use AlarmManager to do this:

Sample code example: (Do some action: just like start an activity in specify time, or you can use PendingIntent.getBroadcast() to create a Broadcast and send)

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// The Activity you want to start
Intent intent = new Intent(MainActivity.this, OtherActivity.class);
// Create pendingIntent
PendingIntent pendingIntent = PendingIntent
        .getActivity(MainActivity.this, 0, intent, 0);
// Set a alarm in specify time
alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAtMillis, pendingIntent);

For more information, visit the official website: AlarmManager

codezjx
  • 9,012
  • 5
  • 47
  • 57
  • Oh i think it should work. Can you show me example as I described in question? It'll help me alot! I'll accept your answer! – Ajinkya More May 05 '15 at 17:05
  • If you want the imageview move with the passage of time, you need to use this method: alarmManager.setRepeating (int type, long triggerAtMillis, long intervalMillis, PendingIntent operation). – codezjx May 05 '15 at 17:13
  • But where to set the passage of time? – Ajinkya More May 05 '15 at 17:14