How to start an Android activity when use clicks on Notification?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

142 Views

This example demonstrate about How to start an Android activity when use clicks on NotificationStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {    public static final String ... Read More

Implement multiple conditions in MongoDB?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

184 Views

Let us first create a collection with documents −> db.multipleConditionDemo.insertOne({"_id":1, "Name":"John"}); { "acknowledged" : true, "insertedId" : 1 } > db.multipleConditionDemo.insertOne({"_id":2, "Name":"Carol"}); { "acknowledged" : true, "insertedId" : 2 } > db.multipleConditionDemo.insertOne({"_id":3, "Name":"Sam"}); { "acknowledged" : true, "insertedId" : 3 } > db.multipleConditionDemo.insertOne({"_id":4, "Name":"David"}); { "acknowledged" : true, "insertedId" : 4 }Following is the query to display all documents from a collection with the help of find() method −> db.multipleConditionDemo.find().pretty();This will produce the following output −{ "_id" : 1, "Name" : "John" } { "_id" : 2, "Name" : "Carol" } { "_id" : 3, "Name" : "Sam" } { ... Read More

How to understand StringBuffer is thread-safe and StringBuilder is non-thread-safe in Java?\

raja
Updated on 30-Jul-2019 22:30:26

3K+ Views

StringBuffer(Thread-safe)StringBuffer is thread-safe meaning that they have synchronized methods to control access so that only one thread can access StringBuffer object's synchronized code at a time.StringBuffer objects are generally safe to use in a multi-threaded environment where multiple threads may be trying to access the same StringBuffer object at the same time.StringBuilder(Non-thread-safe)StringBuilder is not synchronized so that it is not thread-safe. By not being synchronized, the performance of StringBuilder can be better than StringBuffer.If we are working in a single-threaded environment, using StringBuilder instead of StringBuffer may result in increased performance. This is also true of other situations such as ... Read More

How to create Glue to fill the space between neighbouring components in Java?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

347 Views

Let’s say we have 6 components and we need to fill the space between some of them −JButton button1 = new JButton("CSK"); JButton button2 = new JButton("DC"); JButton button3 = new JButton("MI"); JButton button4 = new JButton("SRH"); JButton button5 = new JButton("RR"); JButton button6 = new JButton("KKR");To fill the space and separate components, create a Glue using the createGlue() method −Box box = new Box(BoxLayout.X_AXIS); box.add(button1); box.add(button2); box.add(Box.createGlue()); box.add(button3); box.add(button4); box.add(Box.createGlue()); box.add(button5); box.add(button6);The following is an example to fill the space between neighbouring components −Examplepackage my; import java.awt.BorderLayout; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class ... Read More

Decrement only a single value in MongoDB?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

583 Views

Let us first create a collection with documents −>db.decrementingOperationDemo.insertOne({"ProductName":"Product-1", "ProductPrice":756}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a8ae6d78f205348bc63c") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-2", "ProductPrice":890}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a8b86d78f205348bc63d") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-3", "ProductPrice":994}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a8c66d78f205348bc63e") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-4", "ProductPrice":1000}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7a8d06d78f205348bc63f") }Following is the query to display all documents from a collection with the help of find() method −> db.decrementingOperationDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd7a8ae6d78f205348bc63c"),    "ProductName" : "Product-1",    "ProductPrice" : 756 } {    "_id" : ObjectId("5cd7a8b86d78f205348bc63d"),    "ProductName" ... Read More

HTML tag
Arjun Thakur
Updated on 30-Jul-2019 22:30:26

157 Views

The tag is used to scroll text or image vertically or horizontally on the web page. For example, Breaking news, Popular Articles, etc. These sections are generally displayed scrolling from left to right.Note: The tag deprecated in HTML5.Following are the attributes:AttributeValueDescriptionbehaviorscrollslidealternateDefines the type of scrolling.bgcolorrgb(x, x, x)#xxxxxxcolornameDeprecated − Defines the direction of scrolling the content.directionupdownleftrightDefines the direction of scrolling the content.heightpixels or %Defines the height of marquee.hspacepixelsSpecifies horizontal space around the marquee.loopnumberSpecifies how many times to loop. The default value is INFINITE, which means that the marquee loops endlessly.scrolldelaysecondsDefines how long to delay between each jump.scrollamountnumberDefines how how ... Read More

Can we cast a double value to a byte in java?

Venkata Sai
Updated on 30-Jul-2019 22:30:26

3K+ Views

Java provides various datatypes to store various data values. It provides 7 primitive datatypes (stores single values) namely, boolean, byte, char, short, int, long, float, double and, reference datatypes (arrays and objects).Casting in JavaConverting one primitive data type into another is known as type casting. There are two types of casting −Widening− Converting a lower datatype to a higher datatype is known as widening. It is done implicitly.Narrowing− Converting a higher datatype to a lower datatype is known as narrowing. You need to do it explicitly using the cast operator (“( )”).Casting double to byteDouble is a higher datatype compared ... Read More

C++ Program to count Vowels in a string using Pointer?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

437 Views

To get the vowels from a string, we have to iterate through each character of the string. Here we have to use pointers to move through the string. For this we need C style strings. If the string is pointed by str, then *str will hold the first character at the beginning. Then if str is increased, the *str will point next character and so on. If the character is in [a, e, i, o, u] or [A, E, I, O, U] then it is vowel. So we will increase the countAlgorithmcountVowels(str)begin    count := 0    for each character ... Read More

HTML DOM Location protocol Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

51 Views

The Location protocol property returns/sets a string corresponding to the protocol used for a URL. Protocol can be set to ‘file:’, ‘http:’, ‘https:’, etc..SyntaxFollowing is the syntax −Returning value of the protocol propertylocation.protocolValue of the protocol property setlocation.protocol = protocolStringExampleLet us see an example for Location protocol property − Live Demo Location protocol    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

Create JList and always display the scroll bar in Java?

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

324 Views

To always display the scroll bar in a JList, use the properties HORIZONTAL_SCROLLBAR_ALWAYS and VERTICAL_SCROLLBAR_ALWAYS:JList list = new JList(sports); JScrollPane scrollPane = new JScrollPane(list); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);The following is an example to create JList and display the scroll bar:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void main(String[] args) {       frame = new JFrame("JList Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       String sports[]= {"Tennis", "Archery", "Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"};       list = new JList(sports);       ... Read More

Advertisements