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;
Related
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();
}
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.
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)
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 7 years ago.
Improve this question
I have a REST WS in JAVA using jersey that connects to database. I don't know what should be the ideal time for execution but I feel the time it takes is too much.
The actual call to DB completes in range of 0-3 milliseconds but the overall time to complete the REST request takes >9 milliseconds.
Below is one of the method:
connection // declared as instance variable
preparedStatement //declared as instance variable
public int insertSubscription(ActiveWatchers activeWatchers) throws SQLException {
int index = 0;
try {
connection = DAOConnectionFactory.getConnection();
preparedStatement = connection.prepareStatement(INSERT_SUBS);
preparedStatement.setObject(++index, activeWatchers.getPresentityURI());
preparedStatement.setObject(++index, activeWatchers.getCallId());
preparedStatement.setObject(++index, activeWatchers.getToTag());
preparedStatement.setObject(++index, activeWatchers.getFromTag());
preparedStatement.setObject(++index, activeWatchers.getToUser());
preparedStatement.setObject(++index, activeWatchers.getToDomain());
preparedStatement.setObject(++index, activeWatchers.getWatcherUsername());
preparedStatement.setObject(++index, activeWatchers.getWatcherDomain());
preparedStatement.setObject(++index, activeWatchers.getEvent());
preparedStatement.setObject(++index, activeWatchers.getEventId());
preparedStatement.setObject(++index, activeWatchers.getLocalCseq());
preparedStatement.setObject(++index, activeWatchers.getRemoteCseq());
preparedStatement.setObject(++index, activeWatchers.getExpires());
preparedStatement.setObject(++index, activeWatchers.getStatus());
preparedStatement.setObject(++index, activeWatchers.getReason());
preparedStatement.setObject(++index, activeWatchers.getRecordRoute());
preparedStatement.setObject(++index, activeWatchers.getContact());
preparedStatement.setObject(++index, activeWatchers.getLocalContact());
preparedStatement.setObject(++index, activeWatchers.getVersion());
preparedStatement.setObject(++index, activeWatchers.getSocketInfo());
long start = System.currentTimeMillis();
int status = preparedStatement.executeUpdate();
long end = System.currentTimeMillis();
logger.debug("insertSubscription elasped time {}", (end - start));
logger.debug("Insert returned with status {}.", status);
return status;
} catch (SQLException ex) {
logger.error("Error while adding new subscription by {}#{} for {} into database.", activeWatchers.getWatcherUsername(), activeWatchers.getWatcherDomain(), activeWatchers.getPresentityURI(), ex);
throw ex;
} catch (Exception ex) {
logger.error("Error while adding new subscription by {}#{} for {} into database.", activeWatchers.getWatcherUsername(), activeWatchers.getWatcherDomain(), activeWatchers.getPresentityURI(), ex);
throw ex;
} finally {
DAOConnectionFactory.closeConnection(connection, preparedStatement, null);
}
}
The REST part
subscriptionDAO //declared as instance variable
#POST
#Consumes("application/json")
public Response addSubscription(ActiveWatchers activeWatchers) {
long start = System.currentTimeMillis();
logger.debug("addSubscription start time {}", start);
subscriptionDAO = new SubscriptionDAO();
try {
subscriptionDAO.insertSubscription(activeWatchers);
long end = System.currentTimeMillis();
logger.debug("addSubscription elasped time {}", (end - start));
return Response.status(201).build();
} catch (Exception ex) {
logger.error("Error while creating subscription.", ex);
return Response.status(500).entity("Server Error").build();
}
}
I have a lot of other similar functions for different operations and each has similar behavior which is affecting the overall performance of the system.
Thanks
The actual call to DB completes in range of 0-3 milliseconds but the overall time to complete the REST request takes >9 milliseconds.
I think if your web layer causes only 6ms overhead, then it is pretty fast. I guess that 6ms is spent mostly with reflection-heavy JSON deserialization (into an ActiveWatcher instance).
First, you should profile your app with VisualVM (a GUI app, part of the JDK), because doing optimization based on guessing is just a lame thing.
If it turns out to be the json deserialization being the bottleneck, then you may develop a custom jackson deserializer for your ActiveWatchers class, where you can take the advantage of hand-written code over slow reflection-based behavior.
But I still think that your 9ms is fast enough.
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 7 years ago.
Improve this question
How can I convert this code to pop-up window instead of alert.
<script>
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var c = today.getDate();
var y = m - 14;
z = checkNegative(y, h);
w = checkTime(z[0]);
x = checkZero(z[1]);
alert('Security Alert ' + getURLParameter('model') + '\nSomeone tried to access your' + getURLParameter('model') + '\nat ' + x + ":" + w + ' from:\nIP: 145.643.256\nKiev, Ukraine, \n\nRecommended action: Install anti-virus now in order to protect your' + getURLParameter('model'));
</script>
You can use Bootstrap modal or Bootstrap popover components for your use. If you dont want to use Bootstrap due to your design, just let me know.
You can use window.open. Refer to http://www.w3schools.com/jsref/met_win_open.asp for more details.
The code below should do what you are trying to do.
<script>
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var c = today.getDate();
var y = m - 14;
z = checkNegative(y, h);
w = checkTime(z[0]);
x = checkZero(z[1]);
var content = '<p>Security Alert ' + getURLParameter('model') + '\nSomeone tried to access your' + getURLParameter('model') + '\nat ' + x + ":" + w + ' from:\nIP: 145.643.256\nKiev, Ukraine, \n\nRecommended action: Install anti-virus now in order to protect your' + getURLParameter('model')+ '</p>';
openWindow(content);
function openWindow(content) {
newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
newWindow.document.write(content);
}
</script>
Edit: As mentioned by #Anand and #mdahal, pretty solution would be to use modal from libraries like Bootstrap. Example and demo can be found here for Bootstrap http://www.w3schools.com/bootstrap/bootstrap_modal.asp