Start activity after 15 minutes [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
Hello can someone help me? I'm trying to create an QR Scanner mobile app (java) that after scanning the QR, then verify if 15 minutes of time has passed, it will start a new activity or it will go to new activity.
I tried to set a textview that displays the current time and date, but I do not know how to do the time comparison that will start a new activity after 15 minutes by scanning the QR.
I have a logic below:
if time is not above 15 minutes (9:00 - 9:14), then the current activity will remain.
if time is above 15 minutes (9:15 onwards), new activity will start.
can someone help me? Thank you very much.
And here is my code that I tried:
//Initialize intent result
IntentResult intentResult = IntentIntegrator.parseActivityResult(
requestCode, resultCode, data
);
//check condition
if (intentResult.getContents() != null) {
Intent intent = new Intent(QR_Scanner.this, Present.class);
startActivity(intent);
//from here after checking the time if it is not above 15 minutes, then new activity will start.
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(QR_Scanner.this, Late.class);
startActivity(intent);
}
}, ((1000 * 60) * 5)); //5 minutes delay, after 5 mins idle
} else {
//when result content is null
//display toast
Toast.makeText(getApplicationContext()
, "YOu did not scanned any QR Code. Try again!", Toast.LENGTH_SHORT).show();
}

Related

how can i stop two or multiple people booking the same parking slot [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am working on Parking Slot Reservation System. My project is working properly but I am facing one problem when ever user request slot it first check slot status if slot status is free then it move user to next reservation activity but problem is that if two or multiple user try at the same time then all move to next reservation activity and all reserve one slot at same time. I want only one user will be Able to reserve slot at one time . Here is my code
DatabaseReference reference=FirebaseDatabase.getInstance().getReference().child("parkingslots").child(slotkey);
if(reference.child("status").equals("free")) {
HashMap<String, String> map = new HashMap<>();
map.put("car_number", cnumber);
map.put("date", d + "/" + m + "/" + y);
map.put("entrance_time", h1 + ":" + m1 + ":" + am_pm1);
map.put("exit_time", h2 + ":" + m2 + ":" + am_pm2);
map.put("payment_status", "pending");
map.put("slot_id", slotkey);
map.put("user_id", uid);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("booking").push();
ref.setValue(map);
reference.child("status").setValue("booked");
Toast.makeText(this, "Slot Booked", Toast.LENGTH_LONG).show();
Intent i = new Intent(Booking.this, MainActivity.class);
startActivity(i);
finish();
} else {
Toast.makeText(this, "Sorry! Slot just booked", Toast.LENGTH_LONG).show();
Intent i = new Intent(Booking.this, MainActivity.class);
startActivity(i);
finish();
}
You'll want to:
Use a transaction in your client-side code, to ensure only one client can ever claim the parking spot.
Use security rules on the server, that only the owner can overwrite an existing reservation.

how to avoid download redundant data using volley? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am using volley for parsing json data, while searching i come across how to avoid redundant data form URL, does volley has inbuilt function to do like that or we have to do explicitly like below any help?
requestQueue.getCache().invalidate(url,true);
requestQueue.add(jsonObjectRequest);
please go through this thread: caching using volley
Here he is caching the data
Here is some code of caching after getting response:
Cache.Entry cacheEntry = HttpHeaderParser.parseCacheHeaders(response);
if (cacheEntry == null) {
cacheEntry = new Cache.Entry();
}
final long cacheHitButRefreshed = 3 * 60 * 1000; // in 3 minutes cache will be hit, but also refreshed on background
final long cacheExpired = 24 * 60 * 60 * 1000; // in 24 hours this cache entry expires completely
long now = System.currentTimeMillis();
final long softExpire = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;
cacheEntry.data = response.data;
cacheEntry.softTtl = softExpire;
cacheEntry.ttl = ttl;

com.parse.ParseException: bolts.ExecutorException: An exception was thrown by an Executor [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
The similar code below is working in my app which I have developed 3-yrs back, Do I need to add and dependencies files Or is there an other way of implementing it.I have found this.
private void appLevel_Lang(final Context cntxt) {
final ParseQuery<ParseObject> query = ParseQuery.getQuery("appSupportedLanguages");
query.setLimit(100);
// Get last updated date of appSupportedLanguage table from sqllite
Date dbLastUpdatedDate = db.getLastUpdateDateOfTable("appSupportedLanguages");
if (dbLastUpdatedDate != null) {
query.whereGreaterThan("updatedAt", dbLastUpdatedDate);
}
query.orderByAscending("updatedAt");
// run in background
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> applvl_LangList, ParseException e) {
if (e == null) {
if (applvl_LangList.size() > 0) {
String lastUpdatedDate = ParseQueries.getNSDateFormatterUpdateAtForParse().format(applvl_LangList.get(applvl_LangList.size() - 1).getUpdatedAt());
for (ParseObject p : applvl_LangList) {
// ****Insert in DB****
AppLevel appLevelLanguage = new AppLevel();
appLevelLanguage.objectID = p.getObjectId();
appLevelLanguage.key = p.getString("key");
appLevelLanguage.updatedAt = lastUpdatedDate;
ArrayList<String> arrLangColNames = (ArrayList<String>) ParseConfig.getCurrentConfig().get("supportedLanguages");
// *Insert in local DB*
db.insertOrUpdateAppSupportedLanguageTable(appLevelLanguage);
}
}
if (applvl_LangList.size() == query.getLimit()) {
appLevel_Lang(cntxt);
} else {
Log.d("", "AppSupportedLanguages is not equal to limit");
}
} else {
*// Show parse exception here*
Log.d("AppSupportedLanguages", "Error: " + e.getMessage());
}
}
});
}
Parse has shutdown their service on January 30, 2017
Form Blog link
we will disable the Parse service on Monday, January 30, 2017.
Throughout the day we will be disabling the Parse API on an app-by-app
basis. When your app is disabled, you will not be able to access the
data browser or export any data, and your applications will no longer
be able to access the Parse API.
Alternate Solutions
Firebase
Buddy
Migration (required your own server with node.js application support)

How to know if a value in firebase has increased or decreased?

I'm developing an android app in which there is this option to Follow/Unfollow a user. Whenever someone follows him, the counter in FirebaseDatabase gets increased by 1 and when someone unfollows him, the counter gets decreased by 1.
I'm trying to notify user every time someone follows him by starting a service as soon as he leave the app and writing the code in the Service.
Here's the code in onCreate() of the Service:
firebaseDatabaseFollowers.child("***").child("***").child("followers").addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
b = sharedPref2.getBoolean(SettingsActivity.KEY_PREF_NOTIF_FOLLOW, true);
Toast.makeText(getBaseContext(), "b: " + String.valueOf(b), Toast.LENGTH_SHORT).show();
if (dataSnapshot.getValue() != null) {
if (String.valueOf(b).equals("true")) {
final int m = (int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE);
Intent notificationIntent = new Intent(getBaseContext(), NotificationARBroadcastReceiver.class);
notificationIntent.putExtra(NotificationARBroadcastReceiver.NOTIFICATION, getNotificationService());
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), m, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, pendingIntent);
}
} else {
Toast.makeText(getBaseContext(), "database is null", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
The notification part is working fine. The only problem is that the notification is delivered even when someone unfollows the user and I don't want this to happen.
So, is there any way to know that if the counter in FirebaseDatabase increased or decreased so that I can notify accordingly?
Please let me know.
I would store a global variable in your app that holds the number of followers that the user currently has. When the database sends down new info, you can compare it to the number you have saved by using if new number > or < than saved number. This could be problematic, however, in case the user goes offline and comes back online after, say 1 user unfollowed and 2 others followed. In this case, the user would just get a +1 follower notification. What I might recommend is sending down the username of the user that followed, just like Instagram does. For example, "John Smith followed you!" or "James Smith unfollowed you!".

Android AlarmManager problem

I'm a new developer android application.I've problem about AlarmManager,I using
AlarmManager to set alert for my application.
I was set time to alert 2 time but my application was alert a one time
example,I'll set alarm at 15.30 and 16.30,My application will alert at 16.30 but not alert at 15.30.I've no idea to fix this problem,I hope someone please tell me to fix this problem
This my code
confirmButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
alarm();
finish();
}
});
This alarm method,I'll get date and time from button and use it to set calendar
private void alarm(){
final String day = mBtnselectDate.getText().toString();
final String time = mBtnselectTime.getText().toString();
y = day.substring(0, 4);
m = day.substring(5, 7);
d = day.substring(8);
ALARM_HOUR = time.substring(0, 2);
ALARM_MINUTE = time.substring(3);
year = Integer.parseInt(y);
month = Integer.parseInt(m);
mon = month - 1;
date = Integer.parseInt(d);
Hour = Integer.parseInt(ALARM_HOUR);
Min = Integer.parseInt(ALARM_MINUTE);
Intent AlarmIntent = new Intent(Organaizer2.this, AlarmReceiver2.class);
AlarmManager AlmMgr = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent Sender = PendingIntent.getBroadcast(Organaizer2.this, 0, AlarmIntent, 0);
Calendar alarmCalendar = Calendar.getInstance();
alarmCalendar.set(Calendar.HOUR_OF_DAY, Hour);
alarmCalendar.set(Calendar.MINUTE, Min);
alarmCalendar.set(Calendar.YEAR, year);
alarmCalendar.set(Calendar.MONTH, mon);
alarmCalendar.set(Calendar.DATE, date);
AlmMgr.set(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), Sender);
}
if you see problem please tell me,Thank you,Arles
Your second alarm is replacing the first alarm, because both use equivalent Intent objects. Add a call to setAction() on your AlarmIntent (BTW, recommended Java style is lowercase first letters for variables) to set a unique action string. You can also try providing a different request code (the first 0 in your call to getBroadcast()), though that parameter is not well documented and I am not sure if it will give you distinct alarms or not.

Categories