<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://waliahimanshu.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://waliahimanshu.github.io/" rel="alternate" type="text/html" /><updated>2026-02-01T22:44:23+00:00</updated><id>https://waliahimanshu.github.io/feed.xml</id><title type="html">Himanshu Walia</title><subtitle>Amusing of writing code, building products, life, android and things..</subtitle><author><name>waliahimanshu</name></author><entry><title type="html">Team topologies summary</title><link href="https://waliahimanshu.github.io/books/2020/11/13/team-topologies.html" rel="alternate" type="text/html" title="Team topologies summary" /><published>2020-11-13T00:00:00+00:00</published><updated>2020-11-13T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/books/2020/11/13/team-topologies</id><content type="html" xml:base="https://waliahimanshu.github.io/books/2020/11/13/team-topologies.html"><![CDATA[<h3 id="team-topologies-organizing-business-and-technology-teams-for-fast-flow-by-manuel-pais-and-matthew-skelton">Team topologies: Organizing Business and Technology Teams for Fast Flow by Manuel Pais and Matthew Skelton</h3>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Books">Books</a></p>
</div>
 
  
</div>

<h3 id="chapter-1---the-problem-with-org-charts">Chapter 1 - The problem with org charts</h3>

<p>Modern IT organizations must deliver and operate
software systems rapidly and safely, while simultaneously growing and adapting changes and pressures in the business or regulatory environment</p>

<h4 id="communication-structures-of-an-organization">Communication Structures of an Organization</h4>

<p>It usually shows hierarchical lines of reporting, which imply lines of communication running “up and down” the organization.</p>

<p>In reality people don’t restrict their communications only to those connected
lines on the chart. They reach out to whomever we depend on to get work done. They bend the rules when required to achieve our goals. That’s why actual communication lines look quite different from the org chart</p>

<h4 id="org-chart-thinking-is-the-problem">Org Chart Thinking Is the Problem</h4>

<p>Decisions based on org-chart structure tend to optimize for only part of
the organization, ignoring upstream and downstream effects. Local optimizations help the teams directly involved, but they don’t necessarily help improve the overall delivery of value to customers. For example, having teams adopting cloud and infrastructure-as-code can reduce the time to provision new infrastructure from weeks or months to minutes or
hours. But if every change requires deployment (to production) approval from a board that meets once a week, then delivery speed will remain weekly at best.</p>

<p>Thinking of the org chart as a faithful representation of how work gets done and how teams interact with each other leads to ineffective decisions around allocation of work and responsibilities. Much like a software architecture document gets outdated as soon as the actual software development starts, an org chart is always out of sync with reality.</p>

<p>So if org charts are not an accurate representation of organizational structures, what is? Niels Pflaeging, author of Organize for Complexity, identifies not one but three different organizational structures in every organization:?</p>

<ol>
  <li>Formal structure (the org chart)—facilitates compliance</li>
  <li>Informal structure—the “realm of influence” between individuals</li>
  <li>Value creation structure—how work actually gets done based on inter-personal and inter-team reputation</li>
</ol>

<h4 id="team-topologies-a-new-way-of-thinking-about-teams">Team Topologies: A New Way of Thinking about Teams</h4>
<p>Team Topologies provides four fundamental team types—stream-aligned, platform,
enabling, and complicated-subsystem—and three core team interaction modes
—collaboration, X-as-a-Service, and facilitating. Together with awareness of Conway’s law, <em>team cognitive load</em>, and <em>how to become a sensing organization</em>, Team Topologies results in an effective and humanistic approach to building and running software systems.</p>

<h4 id="the-revival-of-conways-law">The Revival of Conway’s Law</h4>
<p>What is conway’s Law :</p>

<p>“Organizations which design systems .. . are
constrained to produce designs which are copies of the communication structures ofthese organizations.”</p>

<h3 id="chapter-2-conways-law-and-why-it-matters">Chapter 2: Conway’s Law and Why It Matters”.</h3>

<h3 id="chapter-3-team-first-thinking">Chapter 3: Team-First Thinking</h3>

<p>Google on their own teams found that who is on the team matters less than
the team dynamics; and that when it comes to measuring performance, teams matter more than individuals.? We must, therefore, start with the team for effective software delivery. There are multiple aspects to consider and nurture: <em>team size, team lifespan, team relationships, and team cognition</em>.</p>

<h4 id="use-small-long-lived-teams-as-the-standard">Use Small, Long-Lived Teams as the Standard</h4>
<p>Team has a very specific meaning. By team, we mean a stable grouping of
five to nine people who work toward a shared goal as a unit. In most organizations, an effective team has a maximum size of around <strong>seven to nine</strong> people. Dunbar found <em>fifteen to be the limit</em> of the number of people one person can trust deeply.” From those, only around five people can be known and trusted closely.</p>

<p>Allowing teams to grow beyond the magic seven-to-nine size imperils the viability of the software being built by that team, because trust will begin to break down and unsuitable decisions might ensue. Organizations need to maximize trust between people on a team, and that means limiting the number of team members</p>

<h4 id="work-flows-to-long-lived-teams">Work Flows to Long-Lived Teams</h4>

<p>Typically, a team can take from <em>two weeks to three months</em> or more to become a cohesive unit. When (or if) a team reaches that special state, it can be many times more effective than individuals alone. If it takes three months
for a team to become highly effective, we need to provide stability around and within the team to allow them to reach that level. Typically, a team can take from two weeks to three months or more to become a cohesive unit. When (or if) a team reaches that special state, it can be many times more effective than individuals alone. Adding new people to a team doesn’t immediately increase its capacity as there is emotional adaption to accommodate each other view points.</p>

<h4 id="team-owns-the-software">Team owns the Software</h4>
<p>Teams may use
shared services at runtime, but every running service, application, or subsystem is owned
by only one team. Awareness of
and ownership over these different time horizons helps a team care for the code more
effectively.</p>

<h4 id="team-members-need-a-team-first-mindset">Team Members Need a Team-First Mindset</h4>
<p>Team members should put the needs of the team above their own.
They should:</p>
<ul>
  <li>Arrive for stand-ups and meetings on time.</li>
  <li>Keep discussions and investigations on track.</li>
</ul>

<p>Encourage a focus on team goals.</p>

<p>Help unblock other team members before starting on new work.
Mentor new or less experienced team members.</p>

<p>Avoid “winning” arguments and, instead, agree to explore options.</p>

<h4 id="embrace-diversity-in-teams">Embrace Diversity in Teams</h4>

<p>Members of diverse backgrounds tend to produce more creative solutions more rapidly and tend to be better at empathizing with other teams’ needs.!”
How ? In the context of discovering new possibilities, having a variety of viewpoints and experiences helps teams traverse the landscape of solutions much more rapidly. As Naomi Stanford, author of Guide to Organisation Design, puts it: “people and organizations benefit from a diverse workforce where differences spark positive energy.”</p>

<h4 id="good-boundaries-minimize-cognitive-load">Good Boundaries Minimize Cognitive Load</h4>
<p><strong>Restrict Team Responsibilities to Match Team Cognitive Load</strong></p>

<p>Ever-increasing size and complexity of codebases that teams have to work with.
This creates an unbounded cognitive load on teams.  Also applies to teams like a  operations or infrastructure team. They can also suffer from excessive
cognitive load in terms of domains of responsibility, number of applications they need to operate, and tools they need to manage.</p>

<p>For software-delivery teams, a team-first approach to cognitive load means limiting the size of the software system that a team is expected to work with; that is, organizations should not allow a software subsystem to grow beyond the cognitive load of the team responsible for the software.</p>

<p><em>Kinds of cognitive load:</em></p>

<ul>
  <li>
    <p>Intrinsic cognitive load—trelates to aspects of the task fundamental to the problem space (e.g., “What is the structure of a Java class?” “How do I create a new method?”)</p>
  </li>
  <li>
    <p>Extraneous cognitive load—relates to the environment in which the task is being done (e.g., “How do I deploy this component again?” “How do I configure this service?”)</p>
  </li>
  <li>
    <p>Germane cognitive load—relates to aspects of the task that need special attention for learning or high performance (e.g., “How should this service interact with the ABC service?”)</p>
  </li>
</ul>

<p>Many organizations do not consider the cognitive load on teams when
assigning responsibility for parts of a software system, instead assuming that by adding more teams to the problem, the cognitive load will be shared across the teams. Instead, the teams will suffer from similar communication and interaction strains</p>

<p>If we stress the team by giving it responsibility for part of the system that is beyond its cognitive load capacity, it ceases to act like a high-performing unit and starts to behave like a loosely associated group of individuals, each trying to accomplish their individual tasks without the space to consider if those are in the team’s best interest.</p>

<h4 id="measure-the-cognitive-load-using-relative-domain-complexity">Measure the Cognitive Load Using Relative Domain Complexity</h4>
<p>“Do you feel like you’re effective and able to respond in a timely fashion to the work you are asked to do?”
Tying to determine the cognitive load of software using simple measures such as lines of code, number of modules, classes, or methods is misguided.</p>

<ol>
  <li>The first heuristic is to assign each domain to a single team. If a domain is too large for a team, instead of splitting responsibilities of a single domain to multiple teams, first split the domain into subdomains and then assign each new subdomain to a single team.</li>
  <li>The second heuristic is that a single team (considering the golden seven-to-nine team size) should be able to accommodate two to three “simple” domains. Because such domains are  procedural, the cost of context switching between domains is more bearable</li>
  <li>The third heuristic is that a team responsible for a complex domain should not have any more domains assigned to them—not even a simple one.
The last heuristic is to avoid a single team responsible for two complicated domains.</li>
</ol>

<h4 id="match-software-boundary-size-to-team-cognitive-load">Match Software Boundary Size to Team Cognitive Load</h4>
<p>Instead of choosing between a monolithic architecture or a microservices
architecture, design the software to fit the maximum team cognitive load. Only then can we hope to achieve sustainable, safe, rapid software delivery. This team-first approach to software boundaries leads to favoring certain styles of software architecture, such as small, decoupled services.</p>

<ol>
  <li>Provide a team-first working environment (physical or virtual).</li>
  <li>Minimize team distractions during the workweek by limiting meetings, reducing emails, assigning a dedicated team or person to support queries, and so forth.</li>
  <li>Change the management style by communicating goals and outcomes rather than
obsessing over the “how”</li>
  <li>Increase the quality of developer experience (DevEx) for other teams using your team’s code and APIs through good documentation, consistency, good UX, and other DevEx practices.</li>
  <li>Use a platform that is explicitly designed to reduce cognitive load for teams building software on top of it.</li>
</ol>

<blockquote>
  <p>Minimize cognitive load for others” is one of the most useful heuristics 
for good software development.</p>
</blockquote>

<h4 id="define-team-apis-that-include-code-documentation-and-user">Define “Team APIs” that Include Code, Documentation, and User</h4>
<p>The team API should explicitly consider usability by other teams: Will other teams find it easy and straightforward to interact with us, or will it be difficult and confusing?
How easy will it be for a new team to get on board with our code and working practices?
How do we respond to pull requests and other suggestions from other teams? Is our team backlog and product roadmap easily visible and understandable by other teams?
For effective team-first ownership of software, teams need to continuously define,advertise, test, and evolve their team API to ensure that it is fit for purpose for the consumers of that API: other teams/memebers.</p>

<p>The team API includes:</p>

<ol>
  <li>Code: runtime endpoints, libraries, clients, UI, etc. produced by the team</li>
  <li>Versioning: how the team communicates changes to its code and services (e.g., using emantic versioning [SemVer] as a “team promise” not to break things)</li>
  <li>Wiki and documentation: especially how-to guides for the software owned by the team</li>
  <li>Practices and principles: the team’s preferred ways of working</li>
  <li>Communication: the team’s approach to remote communication tools, such as chat tools and video conferencing</li>
  <li>Work information: what the team is working on now, what’s coming next, and overall priorities in the short to medium term</li>
  <li>Anything else that other teams need to use to interact with the team</li>
</ol>

<h4 id="facilitate-team-interactions-for-trust-awareness-and-learning">Facilitate Team Interactions for Trust, Awareness, and Learning</h4>

<p>(1) a consciously designed physical and virtual
environment; 
and (2) time away from desks at guilds, communities of practice (a group of
people who regularly get together on a voluntary basis to collectively learn and share knowledge about a domain of interest, internal tech conferences, etc.</p>

<h4 id="explicitly-design-the-physical-and-virtual-environments-to-help-team-interactions">Explicitly Design the Physical and Virtual Environments to Help Team Interactions</h4>
<p>Neither individual cubicles nor fully open-plan seating is generally suitable for teams . We need something better. Teams need the ability to collaborate frequently, internally and only occasionally externally (with other teams). This balance is hard to achieve both in an open-plan layout (no dedicated work area for the team) and in an individual- workspaces layout (time together needs to be planned ahead of time and meeting rooms
are often scarce).
Example : Spotify—talked about how “squads in a tribe are all physically in the same office, normally right next to each other, and the lounge areas nearby promote collaboration between the squads.”°</p>

<p><em>Office design for effective software delivery should accommodate all of the following modes of work: focused individual work, collaborative intra-team work, and collaborative inter-team work.</em></p>

<h4 id="warning-engineering-practices-are-foundational">Warning: Engineering Practices Are Foundational</h4>
<p>At the end of the day, technology teams need to invest in proven team practices like continuous delivery, test-first development, and a focus on software operability and releasability. Without them, all the effort invested in a team-first approach to work and flow will be greatly undermined.</p>

<h3 id="chapter-4-static-team-topologies">Chapter 4 Static team topologies</h3>

<h4 id="team-anti-patterns">Team Anti-Patterns</h4>
<p>The first anti-pattern is ad hoc team design. This includes teams that have grown too large and been broken up as the communication overhead starts taking a toll.
The other common anti-pattern is shuffling team members. This leads to extremely volatile team assembled on a project basis and disassembled immediately afterward,
perhaps leaving one or two engineers behind to handle the “hardening” and maintenance phases of the application(s).</p>

<p>Organizations must design teams intentionally by asking these questions: 
Given our skills, constraints, cultural and engineering maturity, desired software architecture, and
business goals, which team topology will help us deliver results faster and safer?</p>

<h4 id="design-for-flow-of-change">Design for Flow of Change</h4>
<p>Technical staff at Spotify are arranged into small, autonomous, cross-functional squads, each with a long-term mission and comprised of around five to nine people.
Several squads that work on similar areas are collected into a tribe, a sort of affinity grouping of squads. The squads within a tribe are familiar with the work of other squads and coordinate inside the tribe.</p>

<p>Engineers within a tribe with similar skills and competencies share practices through a chapter. So, for example, all the testers across six squads in a tribe could be part of a testers chapter. Line management also happens via chapters, but the line manager (the chapter lead) is also part of the day-to-day work of a squad, not an aloof manager. Spotify also uses a more diffuse “guild,” akin to a community of practice, that can include people
from across multiple tribes, chapters, and squads. “Chapters and guilds . . . [are] the glue
that keeps the company together, [providing] economies of scale without sacrificing too</p>

<h4 id="shape-team-intercommunication-to-enable-flow-and-sensing">Shape Team Intercommunication to Enable Flow and Sensing</h4>
<p>organizations seem to assume that software delivery is a one-way process, leading from specification to design, from
design to coding, from coding to testing and releasing, and from releasing to business as usual (BAU) operation</p>

<p>Assumption that the software-development process has little or nothing to learn from how the software runs
in the live environment is fundamentally flawed. On the contrary, organizations that expose software-development teams to the software running in the live environment
tend to address user-visible and operational problems much more rapidly compared to their siloed competitors</p>

<p>we must . . . ensure delivery teams are cross-functional, with all the skills necessary to design, develop, test, deploy, and operate the system on the same team.”</p>

<p>Organizations that value information feedback from live (production) systems can not only improve their software more rapidly but also develop a heightened
responsiveness to customers and users.</p>

<h4 id="devops-and-the-devops-topologies">DevOps and the DevOps Topologies</h4>

<p>“wall of confusion.” - &gt;
In dev ops word when with software releases being thrown over the “fence” or
“wall” and communication mostly accomplished through tickets</p>

<p>The problem was that many organizations adopting Agile were not explicitly addressing the gap between software delivery speed and operations teams’ capacity to provide resources or deploy updates. The misalignment between teams became more and more evident, leading to poor behaviors and lack of
focus on the flow of work.</p>

<h4 id="devops-topologies">DevOps Topologies</h4>
<p>The DevOps Topologies reflect two key ideas: 
(1) There is no one-size-fits-all approach to structuring teams for DevOps success. The suitability and effectiveness of
any given topology depends on the organization’s context. (2) There are several topologies known to be detrimental (anti-patterns) to DevOps success, as they overlook
or go against core tenets of DevOps. 
In short, there is no “right” topology, but several “bad” topologies for any one organization.</p>

<h4 id="successful-team-patterns">Successful Team Patterns</h4>

<h4 id="feature-teams-require-high-engineering-maturity-and-trust">Feature Teams Require High-Engineering Maturity and Trust</h4>
<p>We consider a feature team to be a cross- functional, cross-component team that can take a customer facing feature from idea all the way to production, making them available to customers and, ideally, monitoring its
usage and performance. Are these a pattern or an anti-pattern? As you might have guessed by now, it depends.</p>

<p>A cross-functional feature team can bring high value to an organization by delivering cross-component, customer-centric features much faster than multiple component teams making their own changes and synchronizing into a single release. But this can only happen when the feature team is self-sufficient, meaning they are able to deliver features into production without waiting for other teams.</p>

<p>The feature team typically needs to touch multiple codebases, which might be owned by different component teams. If the team does not have a high degree of engineering maturity, they might take shortcuts, such as not automating tests for new user workflows
or not following the “boy-scout rule” (leaving the code better than they found it). Over time, this leads to a breakdown of trust between teams as technical debt increases and slows down delivery speed.</p>

<h4 id="product-teams-need-a-support-system">Product Teams Need a Support System</h4>

<p>The key for the team to remain autonomous is for external dependencies to be non-blocking, meaning that new features don’t sit idle, waiting for something to happen
beyond the control of the team. For example, it’s extremely difficult to ensure that a separate QA team will be available to evaluate a new feature exactly when the product
team finishes it. 
Non-blocking dependencies often take the form of self-service capabilities (e.g, around provisioning test environments, creating deployment pipelines, monitoring, etc.) developed and maintained by other teams. These can be consumed independently by the
product teams when they need them.</p>

<h4 id="cloud-teams-dont-create-application-infrastructure">Cloud Teams Don’t Create Application Infrastructure</h4>

<p>Product teams need autonomy to provision their own environments and resources in the cloud, creating new images and templates where necessary. The cloud team might still own the provisioning process—ensuring that the necessary controls, policies, and
auditing are in place</p>

<h4 id="sre-makes-sense-at-scale">SRE Makes Sense at Scale</h4>

<p>Site Reliability Engineering is an approach to the operation and improvement of software applications pioneered by Google to deal with their global, multi-million-user systems. If adopted in full, SRE is significantly different from IT operations of the past, due to its focus on the “error budget” (namely defining what is an acceptable amount of downtime)
and the ability of SRE teams to push back on poor software.</p>

<p>People on SRE teams need excellent coding skills and—crucially—a strong drive (and bandwidth) to automate repetitive Ops tasks using code, thereby continually reducing toil.</p>

<p>The SRE model sets up a healthy and productive interaction between the development and SRE teams by using service-level objectives (SLOs) and error budgets to
balance the speed of new features with whatever work is needed to make the software
reliable.</p>

<blockquote>
  <p>SRE teams are not essential; they are optional.</p>
</blockquote>

<p>The relationship between an SRE team and an
application-development team changes at different
points of the software’s life and even month by month</p>

<p>Initially, the application development
team alone builds and runs the software in production
until the scale merits SRE help. 
During a second stage as the application usage increases,
SRE provides guidance (represented in green) to the
application development team on how to make the
application work better at global scale. Later, SRE becomes fully involved by running and supporting the application (but still collaborating with the application team) when the
scale merits it At this point, the product owner for the application must decide a suitable service-level objective with a corresponding error budget. If at
some point  the application becomes too difficult to support due to lack of operability, or if the application usage drops off, the application team takes on
operational responsibility again.</p>

<blockquote>
  <p>that building and running software systems is a sociotechnical activity, not an assembly line in a factory.</p>
</blockquote>

<h4 id="considerations-when-choosing-a-topology">Considerations When Choosing a Topology</h4>

<ol>
  <li>Technical and Cultural Maturity</li>
  <li>Organization Size, Software Scale, and Engineering Maturity -&gt; Low maturity organizations will need time to acquire the engineering and product development capabilities required for autonomous end-to-end teams. Meanwhile, more specialized teams (development, operations, security, and others) are an acceptable trade-
off, as long as they collaborate closely to minimize wait times and quickly address issues.</li>
</ol>

<p>3.Splitting Responsibilities to Break Down Silos</p>

<p>Sometimes we can remove or lessen dependencies on specific teams by breaking down their set of responsibilities and empowering other teams to take some of them on. For
example, a pattern increasingly adopted in many organizations over the past few years has been to separate the activities of database development (DB Dev) from database administration (DBA).</p>

<p>4.Dependencies and Wait Times between Teams
Spotify relies on a simple spreadsheet to detect and track interdependencies
between squads and tribes. It highlights whether a dependency is on a squad
within the same tribe (acceptable) or in a different tribe (potentially a warning that
team design or work assignment is wrong).</p>]]></content><author><name>waliahimanshu</name></author><category term="Books" /><summary type="html"><![CDATA[Team topologies: Organizing Business and Technology Teams for Fast Flow by Manuel Pais and Matthew Skelton]]></summary></entry><entry><title type="html">Pragmatic programmer summary</title><link href="https://waliahimanshu.github.io/books/2020/11/12/pragmatric-programmer-notes.html" rel="alternate" type="text/html" title="Pragmatic programmer summary" /><published>2020-11-12T00:00:00+00:00</published><updated>2020-11-12T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/books/2020/11/12/pragmatric-programmer-notes</id><content type="html" xml:base="https://waliahimanshu.github.io/books/2020/11/12/pragmatric-programmer-notes.html"><![CDATA[<h3 id="pragmatic-programmer---notes">Pragmatic Programmer - Notes</h3>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Books">Books</a></p>
</div>
 
  
</div>

<h3 id="chapter-1---a-pragmatic-philosophy">Chapter 1 - A Pragmatic Philosophy</h3>

<p>Who are Pragmatic programers
Has attitude, a style,a philosophy of approaching problems and their solutions.
They think beyond the immediate problem, place it in  larger context and seeking out the bigger picture. 
They make intelligent compromises and informed decisions and most importantly take responsibility of everything they do.</p>

<h3 id="1--you-have-agency">1 . You have agency</h3>
<p>Software development appear close to the top of any list of careers where
you have control. Our skills are in demand, our knowledge crosses geographic
boundaries, we can work remotely. Trick is to ask for anything you want from organization and always remember “you can change your organization or change your organization.”
You’re investing in yourself, so doing it while you’re off-the-clock is only reasonable.</p>

<h3 id="2-the-cat-ate-my-source-code">2. The Cat Ate My Source Code</h3>
<p>Team trust - your team needs to be able to trust and rely on you, in a healty team environment you can speak up your mind.
Responsibility - when you accept the responsibility for an outcome, you should expect to be held accountable for it. When you make a mistake (as we all do ) try to offer solutions then blame.
<strong>Provide Options, Don’t Make Lame Excuses</strong>
Before you approach anyone to tell them why something can’t be done, is
late, or is broken, stop and listen to yourself. Talk to the rubber duck on your monitor, or the cat. Does your excuse sound reasonable, or stupid? How’s it going to sound to your boss?
Run through the <em>conversation in your mind</em>. What is the other person likely
to say? Sometimes, you just know what they are going to
say, so save them the trouble.</p>

<h3 id="3-software-entropy---means-amount-of-disorder-in-any-system-software-rot-or-tech-debt">3. Software Entropy - means amount of disorder in any system. Software rot or tech debt.</h3>

<p><em>A broken window Analogy</em> 
One broken window, left unrepaired for any substantial length of time, instills
in the inhabitants of the building a sense of abandonment—So another window gets broken.
People start littering. Graffiti appears. Serious structural damage begins. In
a relatively short span of time, the building becomes damaged beyond the
owner’s desire to fix it, and the sense of abandonment becomes reality.</p>

<p><em>Don’t Live with Broken Windows</em>
Don’t leave “broken windows’’ (bad designs, wrong decisions, or poor code)
unrepaired.  Comment, fix the broken window or comment to suggest the improvements and come back to it. But don’t leave broken windows.</p>

<p><em>A fire fighter analagy</em> : 
The house was immaculate, loaded with priceless antiques
The fire department rushed in to save burning house one day. But before they
dragged their big, dirty hoses into the house, they stopped—with the fire
raging—to roll out a mat between the front door and the source of the fire.
They didn’t want to mess up the carpet.
Now that sounds pretty extreme. Surely the fire department’s first priority is
to put out the fire. But they clearly had assessed
the situation, were confident of their ability to manage the fire, and were
careful not to inflict unnecessary damage to the property. That’s the way it
must be with software: don’t cause collateral damage just because there’s a
crisis of some sort.</p>

<p>If you find yourself working on a project with quite a few broken windows, it’s all too easy to slip into the mindset of “All the rest of this code is crap. By the same token, if you find yourself on a project where the code is
pristinely beautiful—cleanly written, well designed, and elegant—you will
likely take extra special care not to mess it up, just like the firefighters. Even if there’s a fire raging (deadline, release date, trade show demo, etc.),you don’t want to be the first one to make a mess and inflict additional damage.</p>

<h3 id="4-stone-soup-and-boiled-frog">4. Stone soup and boiled frog</h3>
<p><em>Be a Catalyst for Change</em></p>

<p>You may be in a situation where you know exactly what needs doing and how
to do it. The entire system just appears before your eyes—you know it’s right.
But ask permission to tackle the whole thing and you’ll be met with delays
and blank stares. People will form committees, budgets will need approval,
and things will get complicated. Everyone will guard their own resources.
Sometimes this is called “start-up fatigue.’
It’s time to bring out the stones. Work out what you can reasonably ask for.
Develop it well. Once you’ve got it, show people, and let them marvel. Then
say “of course, it would be better if we added…’’ Pretend it’s not important.
Sit back and wait for them to start asking you to add the functionality you
originally wanted. People find it easier to join an ongoing success.</p>

<h3 id="5-good-enough-software">5. Good-Enough Software</h3>
<p>Bug-free software is a myth.
Time, technology, and temperament all conspire against us.
Make good enough for your users, for future maintainers, for your own peace of mind. You’ll find that you are more productive and your users are happier.
Involve Your Users in the Trade-Off</p>

<p>Make Quality a Requirements Issue - As a user,
would you rather (1) wait for them to get all the bugs out, (2) have complex
software and accept some bugs, or (3) opt for simpler software with fewer
defects?</p>

<h3 id="6-your-knowledge-portfolio">6. Your Knowledge Portfolio</h3>
<ul>
  <li>Invest Regularly in Your Knowledge Portfolio</li>
</ul>

<p>The early bird might get the worm, but what happens to the early worm?
Your knowledge and
experience are your most important day-to-day professional assets.
Unfortunately, they’re expiring assets.7 Your knowledge becomes out of date
as new techniques, languages, and environments are developed</p>

<ol>
  <li>Serious investors invest regularly—as a habit.</li>
  <li>Diversification is the key to long-term success. (different domains, disciplines )</li>
  <li>Smart investors balance their portfolios between conservative and highrisk,
high-reward investments. (new languages framework )</li>
  <li>Investors try to buy low and sell high for maximum return.</li>
  <li>Portfolios should be reviewed and rebalanced periodically.</li>
</ol>

<p>** This can be learned. The trick is to make yourself do it initially and
form a habit. Develop a routine which you follow until your brain internalizes
it. At that point, you’ll find yourself sucking up new knowledge automatically **</p>

<p>When learning Critically Analyze What You Read and Hear
trick: ask “why?” at least five times. Ask a question,
and get an answer. Dig deeper by asking “why?”</p>

<h3 id="7-communicate">7. Communicate!</h3>

<p>Having the best ideas, the finest code, or the most
pragmatic thinking is ultimately sterile unless you can communicate with
other people. A good idea is an orphan without effective communication
<strong>A large part of our day is spent communicating, so we need to do it well</strong></p>

<p>Continuously improve your knowledge of your audience as you communicate.Plan what you want to say. Write an outline. Then ask yourself, “Does this
communicate what I want to express to my audience in a way that works.</p>

<p>Make your style of communication and for make it look good (Your company may already have defined style sheets that you can use.).
Communicate well and listen well, when you don’t know Get back to people.</p>

<p>When writing that Pull request description or a slack message or email.
Proofread, check for spelling mistakes. omit un-necessary words. Make is clear and short. User code snippets to explain where necessary</p>

<h3 id="chapter-2---a-pragmatic-approach">Chapter 2 - A Pragmatic Approach</h3>

<h3 id="8-the-essence-of-good-design">8. The Essence of Good Design</h3>
<p>Good design is easier to change .ETC.every design principle out there is a special case of ETC.
Decoupling? Because by isolating concerns we make each easier to change. ETC.
Single responsibility ? Because a change in requirements should not affect other un-related modules. ETC.
Why is naming important? Because good names make code easier to read,
and you have to read it to change it. ETC!</p>

<p>How to train yourself for ETC. It requires some initial conscious reinforcement. Spend a week or so deliberately
asking yourself “did the thing I just did make the overall system easier
or harder to change?” It’s really just thinking about keeping code
decoupled and cohesive.</p>

<h3 id="9-dry-dont-repeat-yourself---the-evils-of-duplication">9. DRY (Don’t repeat yourself) - The Evils of Duplication</h3>
<p>Code is ever changing, requirements change , client change, industry and government regulations change.</p>

<p>Most people assume that maintenance begins when an application is released,
that maintenance means fixing bugs and enhancing features. This is wrong. Programmers are constantly in maintenance mode. Our
understanding changes day by day. New requirements arrive and existing
requirements evolve as we’re heads-down on the project. Perhaps the environment changes. Whatever the reason, maintenance is not a discrete activity, but a routine part of the entire development process.</p>

<p>…..</p>

<h3 id="10-orthogonality">10. Orthogonality</h3>

<h3 id="11-reversibility">11. Reversibility</h3>
<p>Requirements,users, and hardware change faster than we can get the software developed
Most of the time, calls to third-party products are entangled throughout the code. But we really abstracted the idea of a database out—to the point where it simply provides persistence as a service—then you have the flexibility to change horses in midstream</p>

<p><em>Flexible Architecture</em> -&gt; What you can do is make it easy to change. Hide third-party APIs behind your own abstraction layers. Break your code into components: even if you end up deploying them on a single massive server, this approach is a lot easier than taking a monolithic application and splitting it.</p>

<p>But think of code evolution along the same lines as a box full of
Schrödinger’s cats: every decision results in a different version of the
future. 
How many possible futures can your code support? Which ones
are more likely? 
How hard will it be to support them when the time comes?
Dare you open the box?</p>

<h3 id="12-tracer-bullets">12. Tracer Bullets</h3>
<p>Particularly when you’re building something that hasn’t been built before. We use the term tracer bullet development to visually illustrate the need for immediate feedback under actual conditions with a moving goal</p>

<p>Tracer bullets work because they operate in the same environment and under
the same constraints as the real bullets. They get to the target fast, so the
gunner gets immediate feedback. They’re a relatively cheap solution.</p>

<p>Tracer code is not disposable: you write it for keeps. It contains all the error
checking, structuring, documentation, and self-checking that any piece of
production code has. It simply is not fully functional. However, once you have
achieved an end-to-end connection among the components of your system,
you can check how close to the target you are, adjusting if necessary. Once
you’re on target, adding functionality is easy.
Tracer development is consistent with the idea that a project is never finished: there will always be changes required and functions to add. It is an incremental approach.
The tracer code approach has many advantages</p>

<ol>
  <li>Users get to see something working early</li>
  <li>Developers build a structure to work in</li>
  <li>You have an integration platform</li>
  <li>You have something to demonstrate</li>
  <li>You have a better feel for progress</li>
</ol>

<h4 id="tracer-code-versus-prototyping">Tracer Code versus Prototyping</h4>
<p>Prototyping generates disposable code. Tracer code is lean but complete, and forms part of the skeleton of the final system. Think of prototyping as the reconnaissance and intelligence gathering that takes place before a single tracer bullet is fired.</p>

<h3 id="13-prototypes-and-post-it-notes">13. Prototypes and Post-it Notes</h3>
<p>We tend to think of prototypes as code-based, but they don’t always have to
be. Like the car makers, we can build prototypes out of different materials.
Post-it notes are great for prototyping dynamic things such as workflow and
application logic.</p>

<p>But if you find yourself in an environment where you cannot give up the
details, then you need to ask yourself if you are really building a prototype
at all. Perhaps a tracer bullet style of development would be more appropriate
in this case</p>

<p>Anything you aren’t comfortable with. You can prototype:
• Architecture
• New functionality in an existing system
• Structure or contents of external data
• Third-party tools or components
• Performance issues
• User interface design</p>

<p>Prototyping is a learning experience. Its value lies not in the code produced,
but in the lessons learned. That’s really the point of prototyping.</p>

<p><em>How to Use Prototypes</em>
When building a prototype, what details can you ignore?</p>
<ol>
  <li>Correctness - fake data</li>
  <li>Robustness - Edge/error cases not covered</li>
  <li>Style - may skip the guidelines, process etc</li>
</ol>

<p>Prototypes gloss over details, and focus in on specific aspects of the system being considere.</p>

<h4 id="how-not-to-use-prototypes">How Not to Use Prototypes</h4>
<p>Code-based prototyping, make sure that everyone understands that you are writing disposable code.
Prototypes can be deceptively attractive to people who don’t know that they are just prototypes. You
must make it very clear that this code is disposable, incomplete, and unable to be completed.</p>

<h3 id="14-domain-language">14. Domain Language</h3>
<p>So when you force a business person to sign off on a requirements document, or get
them to agree to a set of Cucumber features, you’re doing the equivalent of getting
them to check the spelling in an essay written in Sumerian. They’ll make some random
changes to save face and sign it off to get you out of their office.
Give them code that runs, however, and they can play with it. That’s where their real
needs will surface.</p>

<p>Document using Test Rspec, cucumber, ansible or YAML.</p>

<h3 id="15-estimating">15. Estimating</h3>

<p>To some extent, all answers are estimates. It’s just that some are more
accurate than others. So the first question you have to ask yourself when
someone asks you for an estimate is the context in which your answer will
be taken. Do they need high accuracy, or are they looking for a ballpark figure?</p>

<ol>
  <li>Understand What’s Being Asked</li>
  <li>Break the Model into Components</li>
  <li>Give Each Parameter a Value</li>
  <li>Keep Track of Your Estimating Prowess</li>
  <li>Check requirements</li>
  <li>Analyze risk (and prioritize riskiest items earlier)</li>
  <li>Design, implement, integrate</li>
  <li>Validate with the users</li>
</ol>

<p>Based on that experience, you can refine your initial guess on the number of iterations and what can be included in
each.T he refinement gets better and better each time, and confidence in the
schedule grows along with it. This kind of estimating is often done during the
team’s review at the end of each iterative cycle.</p>

<p>This may not be popular with management, who typically want a single, hardand- fast number before the project even starts. You’ll have to help them understand that the team, their productivity, and the environment will determine the schedule. By formalizing this, and refining the schedule as part of each iteration, you’ll be giving them the most accurate scheduling
estimates you can.</p>

<h4 id="what-to-say-when-asked-for-an-estimate">What to Say When Asked for an Estimate</h4>
<p>You say “I’ll get back to you.”
You almost always get better results if you slow the process down and spend some time going through the steps we describe in this section.</p>

<hr />

<h2 id="the-basic-tools">The basic tools</h2>

<h4 id="plain-text">Plain text</h4>

<p>Keep knowledge in plain text.
HTML, JSON, YAML,and so on are all plain text. All fundamental protocols on the net, such as HTTP, SMTP, IMAP, are all plain text.</p>

<p>• Insurance against obsolescence
• Leverage existing tools
• Easier testing</p>

<h4 id="shell-games">Shell games</h4>
<p>For a programmer manipulating files of text, that workbench is the command
shell.
Shell, you can launch applications, debuggers, browsers,
editors, and utilities. You can search for files, query the status of the system,and filter output. And by programming the shell, you can build complex macro
commands for activities you perform often</p>

<p>A benefit of GUIs is WYSIWYG—what you see is what
you get. The disadvantage is WYSIAYG—what you see is all you get</p>

<blockquote>
  <p>Use the Power of Command Shells
Gain familiarity with the shell, and you’ll find your productivity soaring.
Color theme, alias, command completion, macros to do repetitive tasks</p>
</blockquote>

<h4 id="power-editing">Power Editing</h4>
<p>use as many editors as you want. We’d just like you to be working toward fluency in each.</p>
<blockquote>
  <p>Achieve Editor Fluency</p>
</blockquote>

<p>• When editing text, move and make selections by character, word, line, and paragraph.
• When editing code, move by various syntactic units (matching delimiters, functions, modules, …).
• Re-indent code following changes.
• Comment and uncomment blocks of code with a single command.
• Undo and redo changes.
• Split the editor window into multiple panels, and navigate between them.
• Navigate to a particular line number.
• Sort selected lines.
• Search for both strings and regular expressions, and repeat previous searches.
• Temporarily create multiple cursors based on a selection or on a pattern match, and edit the text at each in parallel.
• Display compilation errors in the current project.
• Run the current project’s tests</p>

<h4 id="version-control">Version Control</h4>
<blockquote>
  <p>Tip 28 Always Use Version Control and use it for everything. documentation,
phone number lists, memos to vendors, makefiles, build and release procedures,
that little shell script that tidies up log files—everything</p>
</blockquote>]]></content><author><name>waliahimanshu</name></author><category term="Books" /><summary type="html"><![CDATA[Pragmatic Programmer - Notes]]></summary></entry><entry><title type="html">Dialog fragment and custom positioning</title><link href="https://waliahimanshu.github.io/android/2020/09/21/alert-dailog-fragment.html" rel="alternate" type="text/html" title="Dialog fragment and custom positioning" /><published>2020-09-21T00:00:00+00:00</published><updated>2020-09-21T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2020/09/21/alert-dailog-fragment</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2020/09/21/alert-dailog-fragment.html"><![CDATA[<h3 id="alert-dialog">Alert dialog</h3>
<p>Use it when you just want to show a <code class="language-plaintext highlighter-rouge">title</code>, up to three <code class="language-plaintext highlighter-rouge">buttons</code>, a list of <code class="language-plaintext highlighter-rouge">selectable items</code>, or a <code class="language-plaintext highlighter-rouge">custom layout</code>.</p>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<p>Also <code class="language-plaintext highlighter-rouge">DatePickerDialog</code> and <code class="language-plaintext highlighter-rouge">TimePickerDialog</code> are available with a pre-defined android style widgets, that allows the user to select a date or time.</p>

<h3 id="dialogfragment">DialogFragment</h3>

<p>Use a DialogFragment as a container for your dialog, when you need</p>
<ul>
  <li>to ensures that it correctly handles lifecycle events such as when the user presses the back button or rotates the screen.</li>
  <li>to allow reuse the dialog’s UI just like in a traditional Fragment (such as when you want the dialog UI to appear differently on large and small screens).</li>
</ul>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">FireMissilesDialogFragment</span> <span class="p">:</span> <span class="no">DialogFragment</span><span class="p">()</span> <span class="p">{</span>

    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateDialog</span><span class="p">(</span><span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">):</span> <span class="no">Dialog</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">requireActivity</span><span class="p">()?.</span><span class="nf">let</span> <span class="p">{</span>
            <span class="sr">//</span> <span class="no">Use</span> <span class="n">the</span> <span class="no">Builder</span> <span class="k">class</span> <span class="k">for</span> <span class="n">convenient</span> <span class="n">dialog</span> <span class="n">construction</span>
            <span class="n">val</span> <span class="n">builder</span> <span class="o">=</span> <span class="no">AlertDialog</span><span class="o">.</span><span class="no">Builder</span><span class="p">(</span><span class="n">it</span><span class="p">)</span>
            <span class="n">builder</span><span class="p">.</span><span class="nf">setMessage</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">dialog_fire_missiles</span><span class="p">)</span>
                    <span class="p">.</span><span class="nf">setPositiveButton</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">fire</span><span class="p">,</span>
                            <span class="no">DialogInterface</span><span class="o">.</span><span class="no">OnClickListener</span> <span class="p">{</span> <span class="n">dialog</span><span class="p">,</span> <span class="nb">id</span> <span class="o">-&gt;</span>
                            <span class="p">})</span>
                    <span class="p">.</span><span class="nf">setNegativeButton</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">cancel</span><span class="p">,</span>
                            <span class="no">DialogInterface</span><span class="o">.</span><span class="no">OnClickListener</span> <span class="p">{</span> <span class="n">dialog</span><span class="p">,</span> <span class="nb">id</span> <span class="o">-&gt;</span>
                                <span class="sr">//</span> <span class="no">User</span> <span class="n">cancelled</span> <span class="n">the</span> <span class="n">dialog</span>
                            <span class="p">})</span>
            <span class="sr">//</span> <span class="no">Create</span> <span class="n">the</span> <span class="no">AlertDialog</span> <span class="n">object</span> <span class="n">and</span> <span class="k">return</span> <span class="n">it</span>
            <span class="n">builder</span><span class="p">.</span><span class="nf">create</span><span class="p">()</span>
        <span class="p">}</span> <span class="p">?:</span> <span class="kp">throw</span> <span class="no">IllegalStateException</span><span class="p">(</span><span class="s2">"Activity cannot be null"</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span> 

<span class="sr">//</span> <span class="no">Showing</span> <span class="n">a</span> <span class="no">Dialog</span>

<span class="n">fun</span> <span class="n">confirmFireMissiles</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">val</span> <span class="n">newFragment</span> <span class="o">=</span> <span class="no">FireMissilesDialogFragment</span><span class="p">()</span>
    <span class="n">newFragment</span><span class="p">.</span><span class="nf">show</span><span class="p">(</span><span class="n">supportFragmentManager</span><span class="p">,</span> <span class="s2">"missiles"</span><span class="p">)</span>
<span class="p">}</span>

</code></pre></div></div>

<p>The show method add the fragment in transaction and commits,
however you can not pop back this fragment from stack.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">CustomDialogFragment</span> <span class="p">:</span> <span class="no">DialogFragment</span><span class="p">()</span> <span class="p">{</span>

    <span class="sr">/** The system calls this to get the DialogFragment's layout, regardless
    of whether it's being displayed as a dialog or an embedded fragment. */</span>
    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateView</span><span class="p">(</span>
            <span class="ss">inflater: </span><span class="no">LayoutInflater</span><span class="p">,</span>
            <span class="ss">container: </span><span class="no">ViewGroup</span><span class="p">?,</span>
            <span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">?</span>
    <span class="p">):</span> <span class="no">View</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">Inflate</span> <span class="n">the</span> <span class="n">layout</span> <span class="n">to</span> <span class="n">use</span> <span class="n">as</span> <span class="n">dialog</span> <span class="n">or</span> <span class="n">embedded</span> <span class="n">fragment</span>
        <span class="k">return</span> <span class="n">inflater</span><span class="p">.</span><span class="nf">inflate</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">layout</span><span class="p">.</span><span class="nf">purchase_items</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="kp">false</span><span class="p">)</span>
    <span class="p">}</span>

    <span class="sr">/** The system calls this only when creating the layout in a dialog. */</span>
    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateDialog</span><span class="p">(</span><span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">):</span> <span class="no">Dialog</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">only</span> <span class="n">reason</span> <span class="n">you</span> <span class="n">might</span> <span class="n">override</span> <span class="n">this</span> <span class="nb">method</span> <span class="k">when</span> <span class="n">using</span> <span class="n">onCreateView</span><span class="p">()</span> <span class="n">is</span>
        <span class="sr">//</span> <span class="n">to</span> <span class="n">modify</span> <span class="n">any</span> <span class="n">dialog</span> <span class="n">characteristics</span><span class="o">.</span> <span class="no">For</span> <span class="n">example</span><span class="p">,</span> <span class="n">the</span> <span class="n">dialog</span> <span class="n">includes</span> <span class="n">a</span>
        <span class="sr">//</span> <span class="n">title</span> <span class="n">by</span> <span class="n">default</span><span class="p">,</span> <span class="n">but</span> <span class="n">your</span> <span class="n">custom</span> <span class="n">layout</span> <span class="n">might</span> <span class="n">not</span> <span class="n">need</span> <span class="n">it</span><span class="o">.</span> <span class="no">So</span> <span class="n">here</span> <span class="n">you</span> <span class="n">can</span>
        <span class="sr">//</span> <span class="n">remove</span> <span class="n">the</span> <span class="n">dialog</span> <span class="n">title</span><span class="p">,</span> <span class="n">but</span> <span class="n">you</span> <span class="n">must</span> <span class="n">call</span> <span class="n">the</span> <span class="n">superclass</span> <span class="n">to</span> <span class="n">get</span> <span class="n">the</span> <span class="no">Dialog</span><span class="p">.</span>
        <span class="nf">val</span> <span class="n">dialog</span> <span class="o">=</span> <span class="k">super</span><span class="p">.</span><span class="nf">onCreateDialog</span><span class="p">(</span><span class="n">savedInstanceState</span><span class="p">)</span>
        <span class="n">dialog</span><span class="p">.</span><span class="nf">requestWindowFeature</span><span class="p">(</span><span class="no">Window</span><span class="o">.</span><span class="no">FEATURE_NO_TITLE</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">dialog</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">fun</span> <span class="n">showDialog</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">val</span> <span class="n">fragmentManager</span> <span class="o">=</span> <span class="n">supportFragmentManager</span>
    <span class="n">val</span> <span class="n">newFragment</span> <span class="o">=</span> <span class="no">CustomDialogFragment</span><span class="p">()</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">isLargeLayout</span><span class="p">)</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">device</span> <span class="n">is</span> <span class="n">using</span> <span class="n">a</span> <span class="n">large</span> <span class="n">layout</span><span class="p">,</span> <span class="n">so</span> <span class="n">show</span> <span class="n">the</span> <span class="n">fragment</span> <span class="n">as</span> <span class="n">a</span> <span class="n">dialog</span>
        <span class="n">newFragment</span><span class="p">.</span><span class="nf">show</span><span class="p">(</span><span class="n">fragmentManager</span><span class="p">,</span> <span class="s2">"dialog"</span><span class="p">)</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">device</span> <span class="n">is</span> <span class="n">smaller</span><span class="p">,</span> <span class="n">so</span> <span class="n">show</span> <span class="n">the</span> <span class="n">fragment</span> <span class="n">fullscreen</span>
        <span class="n">val</span> <span class="n">transaction</span> <span class="o">=</span> <span class="n">fragmentManager</span><span class="p">.</span><span class="nf">beginTransaction</span><span class="p">()</span>
        <span class="sr">//</span> <span class="no">For</span> <span class="n">a</span> <span class="n">little</span> <span class="n">polish</span><span class="p">,</span> <span class="n">specify</span> <span class="n">a</span> <span class="n">transition</span> <span class="n">animation</span>
        <span class="n">transaction</span><span class="p">.</span><span class="nf">setTransition</span><span class="p">(</span><span class="no">FragmentTransaction</span><span class="o">.</span><span class="no">TRANSIT_FRAGMENT_OPEN</span><span class="p">)</span>
        <span class="sr">//</span> <span class="no">To</span> <span class="n">make</span> <span class="n">it</span> <span class="n">fullscreen</span><span class="p">,</span> <span class="n">use</span> <span class="n">the</span> <span class="s1">'content'</span> <span class="n">root</span> <span class="n">view</span> <span class="n">as</span> <span class="n">the</span> <span class="n">container</span>
        <span class="sr">//</span> <span class="k">for</span> <span class="n">the</span> <span class="n">fragment</span><span class="p">,</span> <span class="n">which</span> <span class="n">is</span> <span class="n">always</span> <span class="n">the</span> <span class="n">root</span> <span class="n">view</span> <span class="k">for</span> <span class="n">the</span> <span class="n">activity</span>
        <span class="n">transaction</span>
                <span class="p">.</span><span class="nf">add</span><span class="p">(</span><span class="n">android</span><span class="o">.</span><span class="no">R</span><span class="p">.</span><span class="nf">id</span><span class="p">.</span><span class="nf">content</span><span class="p">,</span> <span class="n">newFragment</span><span class="p">)</span>
                <span class="p">.</span><span class="nf">addToBackStack</span><span class="p">(</span><span class="n">null</span><span class="p">)</span>
                <span class="p">.</span><span class="nf">commit</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="changing-the-position-of-the-dialog">Changing the position of the dialog.</h3>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="kp">private</span> <span class="n">fun</span> <span class="n">setupDialogProperties</span><span class="p">(</span><span class="ss">alertDialog: </span><span class="no">AlertDialog</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">val</span> <span class="no">OFFSET_IN_PX</span> <span class="o">=</span> <span class="mi">140</span>
        <span class="n">alertDialog</span><span class="p">.</span><span class="nf">apply</span> <span class="p">{</span>
            <span class="n">window?</span><span class="p">.</span><span class="nf">let</span> <span class="p">{</span> <span class="n">window</span> <span class="o">-&gt;</span>
                <span class="n">window</span><span class="p">.</span><span class="nf">setBackgroundDrawableResource</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">drawable</span><span class="p">.</span><span class="nf">bg_drawable</span><span class="p">)</span>
                <span class="n">window</span><span class="p">.</span><span class="nf">setDimAmount</span><span class="p">(</span><span class="mf">0.1</span><span class="n">f</span><span class="p">)</span> <span class="o">/</span><span class="sr">/ from 0 for no dim to 1 for full dim.
                window.attributes?.let { params -&gt;
                    params.width = WindowManager.LayoutParams.MATCH_PARENT
                    params.height = WindowManager.LayoutParams.WRAP_CONTENT
                    params.gravity = Gravity.TOP or Gravity.CENTER
                    params.y = (OFFSET_IN_PX).toFloat())
                    params.x = 0
                }
            }
            setCanceledOnTouchOutside(true)
            setCancelable(true)
            requestWindowFeature(Window.FEATURE_NO_TITLE)
        }
    }
</span></code></pre></div></div>]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Alert dialog Use it when you just want to show a title, up to three buttons, a list of selectable items, or a custom layout.]]></summary></entry><entry><title type="html">Notifications in Android</title><link href="https://waliahimanshu.github.io/android/2019/11/21/android-notifications.html" rel="alternate" type="text/html" title="Notifications in Android" /><published>2019-11-21T00:00:00+00:00</published><updated>2019-11-21T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2019/11/21/android-notifications</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2019/11/21/android-notifications.html"><![CDATA[<h3 id="notifications-done-right">Notifications done right</h3>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<p>Notifications are a double edge sword, it can accelerate growth and engagement or could lead to immediate un-install of the app.</p>

<p>With each Android OS version, the notification API’s are changing and OS is increasingly becoming aware of how apps are notifying the users.</p>

<p>Therefore, it is important to get the notifications right in your app.</p>

<h3 id="types-of-notification">Types of notification</h3>

<p>####Transactional:
which are the notifications which are absolutely necessary</p>

<p>Not Transactions</p>

<p>Slides : <a href="https://speakerdeck.com/waliahimanshu/rich-android-notifications">Rich Android notification</a></p>

<hr />

<iframe width="1344" height="492" src="https://www.youtube.com/embed/THC6HnKX_-k" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

<script src="https://gist.github.com/waliahimanshu/c237c1dce48183aa8e88b3c021ff4576.js"></script>

<script src="https://gist.github.com/waliahimanshu/97c7c074367965ad9b241adc9e769fbb.js"></script>

<script src="https://gist.github.com/waliahimanshu/1faaa6f020172217751476432896a114.js"></script>]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Notifications done right]]></summary></entry><entry><title type="html">Dialog fragment and custom positioning</title><link href="https://waliahimanshu.github.io/android/2019/09/21/alert-dailog-fragment.html" rel="alternate" type="text/html" title="Dialog fragment and custom positioning" /><published>2019-09-21T00:00:00+00:00</published><updated>2019-09-21T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2019/09/21/alert-dailog-fragment</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2019/09/21/alert-dailog-fragment.html"><![CDATA[<h3 id="alert-dialog">Alert dialog</h3>
<p>Use it when you just want to show a <code class="language-plaintext highlighter-rouge">title</code>, up to three <code class="language-plaintext highlighter-rouge">buttons</code>, a list of <code class="language-plaintext highlighter-rouge">selectable items</code>, or a <code class="language-plaintext highlighter-rouge">custom layout</code>.</p>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<p>Also <code class="language-plaintext highlighter-rouge">DatePickerDialog</code> and <code class="language-plaintext highlighter-rouge">TimePickerDialog</code> are available with a pre-defined android style widgets, that allows the user to select a date or time.</p>

<h3 id="dialogfragment">DialogFragment</h3>

<p>Use a DialogFragment as a container for your dialog, when you need</p>
<ul>
  <li>to ensures that it correctly handles lifecycle events such as when the user presses the back button or rotates the screen.</li>
  <li>to allow reuse the dialog’s UI just like in a traditional Fragment (such as when you want the dialog UI to appear differently on large and small screens).</li>
</ul>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">FireMissilesDialogFragment</span> <span class="p">:</span> <span class="no">DialogFragment</span><span class="p">()</span> <span class="p">{</span>

    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateDialog</span><span class="p">(</span><span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">):</span> <span class="no">Dialog</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">requireActivity</span><span class="p">()?.</span><span class="nf">let</span> <span class="p">{</span>
            <span class="sr">//</span> <span class="no">Use</span> <span class="n">the</span> <span class="no">Builder</span> <span class="k">class</span> <span class="k">for</span> <span class="n">convenient</span> <span class="n">dialog</span> <span class="n">construction</span>
            <span class="n">val</span> <span class="n">builder</span> <span class="o">=</span> <span class="no">AlertDialog</span><span class="o">.</span><span class="no">Builder</span><span class="p">(</span><span class="n">it</span><span class="p">)</span>
            <span class="n">builder</span><span class="p">.</span><span class="nf">setMessage</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">dialog_fire_missiles</span><span class="p">)</span>
                    <span class="p">.</span><span class="nf">setPositiveButton</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">fire</span><span class="p">,</span>
                            <span class="no">DialogInterface</span><span class="o">.</span><span class="no">OnClickListener</span> <span class="p">{</span> <span class="n">dialog</span><span class="p">,</span> <span class="nb">id</span> <span class="o">-&gt;</span>
                            <span class="p">})</span>
                    <span class="p">.</span><span class="nf">setNegativeButton</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">string</span><span class="p">.</span><span class="nf">cancel</span><span class="p">,</span>
                            <span class="no">DialogInterface</span><span class="o">.</span><span class="no">OnClickListener</span> <span class="p">{</span> <span class="n">dialog</span><span class="p">,</span> <span class="nb">id</span> <span class="o">-&gt;</span>
                                <span class="sr">//</span> <span class="no">User</span> <span class="n">cancelled</span> <span class="n">the</span> <span class="n">dialog</span>
                            <span class="p">})</span>
            <span class="sr">//</span> <span class="no">Create</span> <span class="n">the</span> <span class="no">AlertDialog</span> <span class="n">object</span> <span class="n">and</span> <span class="k">return</span> <span class="n">it</span>
            <span class="n">builder</span><span class="p">.</span><span class="nf">create</span><span class="p">()</span>
        <span class="p">}</span> <span class="p">?:</span> <span class="kp">throw</span> <span class="no">IllegalStateException</span><span class="p">(</span><span class="s2">"Activity cannot be null"</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span> 

<span class="sr">//</span> <span class="no">Showing</span> <span class="n">a</span> <span class="no">Dialog</span>

<span class="n">fun</span> <span class="n">confirmFireMissiles</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">val</span> <span class="n">newFragment</span> <span class="o">=</span> <span class="no">FireMissilesDialogFragment</span><span class="p">()</span>
    <span class="n">newFragment</span><span class="p">.</span><span class="nf">show</span><span class="p">(</span><span class="n">supportFragmentManager</span><span class="p">,</span> <span class="s2">"missiles"</span><span class="p">)</span>
<span class="p">}</span>

</code></pre></div></div>

<p>The show method add the fragment in transaction and commits,
however you can not pop back this fragment from stack.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">CustomDialogFragment</span> <span class="p">:</span> <span class="no">DialogFragment</span><span class="p">()</span> <span class="p">{</span>

    <span class="sr">/** The system calls this to get the DialogFragment's layout, regardless
    of whether it's being displayed as a dialog or an embedded fragment. */</span>
    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateView</span><span class="p">(</span>
            <span class="ss">inflater: </span><span class="no">LayoutInflater</span><span class="p">,</span>
            <span class="ss">container: </span><span class="no">ViewGroup</span><span class="p">?,</span>
            <span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">?</span>
    <span class="p">):</span> <span class="no">View</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">Inflate</span> <span class="n">the</span> <span class="n">layout</span> <span class="n">to</span> <span class="n">use</span> <span class="n">as</span> <span class="n">dialog</span> <span class="n">or</span> <span class="n">embedded</span> <span class="n">fragment</span>
        <span class="k">return</span> <span class="n">inflater</span><span class="p">.</span><span class="nf">inflate</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">layout</span><span class="p">.</span><span class="nf">purchase_items</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="kp">false</span><span class="p">)</span>
    <span class="p">}</span>

    <span class="sr">/** The system calls this only when creating the layout in a dialog. */</span>
    <span class="n">override</span> <span class="n">fun</span> <span class="n">onCreateDialog</span><span class="p">(</span><span class="ss">savedInstanceState: </span><span class="no">Bundle</span><span class="p">):</span> <span class="no">Dialog</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">only</span> <span class="n">reason</span> <span class="n">you</span> <span class="n">might</span> <span class="n">override</span> <span class="n">this</span> <span class="nb">method</span> <span class="k">when</span> <span class="n">using</span> <span class="n">onCreateView</span><span class="p">()</span> <span class="n">is</span>
        <span class="sr">//</span> <span class="n">to</span> <span class="n">modify</span> <span class="n">any</span> <span class="n">dialog</span> <span class="n">characteristics</span><span class="o">.</span> <span class="no">For</span> <span class="n">example</span><span class="p">,</span> <span class="n">the</span> <span class="n">dialog</span> <span class="n">includes</span> <span class="n">a</span>
        <span class="sr">//</span> <span class="n">title</span> <span class="n">by</span> <span class="n">default</span><span class="p">,</span> <span class="n">but</span> <span class="n">your</span> <span class="n">custom</span> <span class="n">layout</span> <span class="n">might</span> <span class="n">not</span> <span class="n">need</span> <span class="n">it</span><span class="o">.</span> <span class="no">So</span> <span class="n">here</span> <span class="n">you</span> <span class="n">can</span>
        <span class="sr">//</span> <span class="n">remove</span> <span class="n">the</span> <span class="n">dialog</span> <span class="n">title</span><span class="p">,</span> <span class="n">but</span> <span class="n">you</span> <span class="n">must</span> <span class="n">call</span> <span class="n">the</span> <span class="n">superclass</span> <span class="n">to</span> <span class="n">get</span> <span class="n">the</span> <span class="no">Dialog</span><span class="p">.</span>
        <span class="nf">val</span> <span class="n">dialog</span> <span class="o">=</span> <span class="k">super</span><span class="p">.</span><span class="nf">onCreateDialog</span><span class="p">(</span><span class="n">savedInstanceState</span><span class="p">)</span>
        <span class="n">dialog</span><span class="p">.</span><span class="nf">requestWindowFeature</span><span class="p">(</span><span class="no">Window</span><span class="o">.</span><span class="no">FEATURE_NO_TITLE</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">dialog</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">fun</span> <span class="n">showDialog</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">val</span> <span class="n">fragmentManager</span> <span class="o">=</span> <span class="n">supportFragmentManager</span>
    <span class="n">val</span> <span class="n">newFragment</span> <span class="o">=</span> <span class="no">CustomDialogFragment</span><span class="p">()</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">isLargeLayout</span><span class="p">)</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">device</span> <span class="n">is</span> <span class="n">using</span> <span class="n">a</span> <span class="n">large</span> <span class="n">layout</span><span class="p">,</span> <span class="n">so</span> <span class="n">show</span> <span class="n">the</span> <span class="n">fragment</span> <span class="n">as</span> <span class="n">a</span> <span class="n">dialog</span>
        <span class="n">newFragment</span><span class="p">.</span><span class="nf">show</span><span class="p">(</span><span class="n">fragmentManager</span><span class="p">,</span> <span class="s2">"dialog"</span><span class="p">)</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">The</span> <span class="n">device</span> <span class="n">is</span> <span class="n">smaller</span><span class="p">,</span> <span class="n">so</span> <span class="n">show</span> <span class="n">the</span> <span class="n">fragment</span> <span class="n">fullscreen</span>
        <span class="n">val</span> <span class="n">transaction</span> <span class="o">=</span> <span class="n">fragmentManager</span><span class="p">.</span><span class="nf">beginTransaction</span><span class="p">()</span>
        <span class="sr">//</span> <span class="no">For</span> <span class="n">a</span> <span class="n">little</span> <span class="n">polish</span><span class="p">,</span> <span class="n">specify</span> <span class="n">a</span> <span class="n">transition</span> <span class="n">animation</span>
        <span class="n">transaction</span><span class="p">.</span><span class="nf">setTransition</span><span class="p">(</span><span class="no">FragmentTransaction</span><span class="o">.</span><span class="no">TRANSIT_FRAGMENT_OPEN</span><span class="p">)</span>
        <span class="sr">//</span> <span class="no">To</span> <span class="n">make</span> <span class="n">it</span> <span class="n">fullscreen</span><span class="p">,</span> <span class="n">use</span> <span class="n">the</span> <span class="s1">'content'</span> <span class="n">root</span> <span class="n">view</span> <span class="n">as</span> <span class="n">the</span> <span class="n">container</span>
        <span class="sr">//</span> <span class="k">for</span> <span class="n">the</span> <span class="n">fragment</span><span class="p">,</span> <span class="n">which</span> <span class="n">is</span> <span class="n">always</span> <span class="n">the</span> <span class="n">root</span> <span class="n">view</span> <span class="k">for</span> <span class="n">the</span> <span class="n">activity</span>
        <span class="n">transaction</span>
                <span class="p">.</span><span class="nf">add</span><span class="p">(</span><span class="n">android</span><span class="o">.</span><span class="no">R</span><span class="p">.</span><span class="nf">id</span><span class="p">.</span><span class="nf">content</span><span class="p">,</span> <span class="n">newFragment</span><span class="p">)</span>
                <span class="p">.</span><span class="nf">addToBackStack</span><span class="p">(</span><span class="n">null</span><span class="p">)</span>
                <span class="p">.</span><span class="nf">commit</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="changing-the-position-of-the-dialog">Changing the position of the dialog.</h3>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="kp">private</span> <span class="n">fun</span> <span class="n">setupDialogProperties</span><span class="p">(</span><span class="ss">alertDialog: </span><span class="no">AlertDialog</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">val</span> <span class="no">OFFSET_IN_PX</span> <span class="o">=</span> <span class="mi">140</span>
        <span class="n">alertDialog</span><span class="p">.</span><span class="nf">apply</span> <span class="p">{</span>
            <span class="n">window?</span><span class="p">.</span><span class="nf">let</span> <span class="p">{</span> <span class="n">window</span> <span class="o">-&gt;</span>
                <span class="n">window</span><span class="p">.</span><span class="nf">setBackgroundDrawableResource</span><span class="p">(</span><span class="no">R</span><span class="p">.</span><span class="nf">drawable</span><span class="p">.</span><span class="nf">bg_drawable</span><span class="p">)</span>
                <span class="n">window</span><span class="p">.</span><span class="nf">setDimAmount</span><span class="p">(</span><span class="mf">0.1</span><span class="n">f</span><span class="p">)</span> <span class="o">/</span><span class="sr">/ from 0 for no dim to 1 for full dim.
                window.attributes?.let { params -&gt;
                    params.width = WindowManager.LayoutParams.MATCH_PARENT
                    params.height = WindowManager.LayoutParams.WRAP_CONTENT
                    params.gravity = Gravity.TOP or Gravity.CENTER
                    params.y = (OFFSET_IN_PX).toFloat())
                    params.x = 0
                }
            }
            setCanceledOnTouchOutside(true)
            setCancelable(true)
            requestWindowFeature(Window.FEATURE_NO_TITLE)
        }
    }
</span></code></pre></div></div>]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Alert dialog Use it when you just want to show a title, up to three buttons, a list of selectable items, or a custom layout.]]></summary></entry><entry><title type="html">Async work on BroadcastReceiver</title><link href="https://waliahimanshu.github.io/android/2019/08/27/goasync-broadcast-receiver.html" rel="alternate" type="text/html" title="Async work on BroadcastReceiver" /><published>2019-08-27T00:00:00+00:00</published><updated>2019-08-27T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2019/08/27/goasync-broadcast-receiver</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2019/08/27/goasync-broadcast-receiver.html"><![CDATA[<p><b>Problem</b>:
I cannot perform any long running operation (aka IO operation) inside BroadcastReceiver as it dies immediately after receiving the intent.</p>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<p><b>Why</b>
<code class="language-plaintext highlighter-rouge">BroadcastReceiver.onReceive</code> always run in the UIthread (also main thread).
That means, you can not perform any long running operation.</p>

<p>However, in only rare cases when you need BroadcastReceiver to live longer, by using <code class="language-plaintext highlighter-rouge">goAsync()</code> we can tell the android framework to keep the receiver for longer approx <code class="language-plaintext highlighter-rouge">30</code> seconds.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">override</span> <span class="n">fun</span> <span class="n">onReceive</span><span class="p">(</span><span class="ss">context: </span><span class="no">Context</span><span class="p">,</span> <span class="ss">intent: </span><span class="no">Intent</span><span class="p">?)</span> <span class="p">{</span>

        <span class="n">val</span> <span class="n">pendingResult</span> <span class="o">=</span> <span class="n">goAsync</span><span class="p">()</span>

        <span class="no">Thread</span><span class="p">(</span><span class="no">Runnable</span> <span class="p">{</span>
          <span class="n">val</span> <span class="nb">id</span> <span class="o">=</span> <span class="n">intent?</span><span class="p">.</span><span class="nf">getStringExtra</span><span class="p">(</span><span class="no">ARG_ID_KEY</span><span class="p">)</span>
            <span class="nb">id</span><span class="p">?.</span><span class="nf">let</span> <span class="p">{</span>
                <span class="sr">//</span> <span class="n">perform</span> <span class="n">long</span> <span class="n">operation</span> <span class="n">task</span>
           <span class="p">}</span>

            <span class="sr">//</span><span class="n">let</span> <span class="n">the</span> <span class="nb">system</span> <span class="n">know</span> <span class="n">the</span> <span class="no">BroadcastReceiver</span> <span class="n">can</span> <span class="n">now</span> <span class="sr">//</span><span class="n">finish</span>
            <span class="n">pendingResult</span><span class="p">.</span><span class="nf">finish</span><span class="p">()</span> 

        <span class="p">}).</span><span class="nf">start</span><span class="p">()</span>
    <span class="p">}</span>
</code></pre></div></div>
<hr />]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Problem: I cannot perform any long running operation (aka IO operation) inside BroadcastReceiver as it dies immediately after receiving the intent.]]></summary></entry><entry><title type="html">Android set multiple alarms using Alarm Manager</title><link href="https://waliahimanshu.github.io/android/2019/08/25/multiple-alarm-android.html" rel="alternate" type="text/html" title="Android set multiple alarms using Alarm Manager" /><published>2019-08-25T00:00:00+00:00</published><updated>2019-08-25T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2019/08/25/multiple-alarm-android</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2019/08/25/multiple-alarm-android.html"><![CDATA[<p><b>Problem</b>:
I am scheduling multiple alarms using <code class="language-plaintext highlighter-rouge">Alarm  Manager</code>, but only one gets triggered.</p>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<p><img src="/assets/arash-asghari-D58BEHSeX64-unsplash.jpg" alt="image-title-here" /></p>

<p>Other day, I was scheduling two alarms simultaneously, at some point in future, but only one was being triggerd.</p>

<h3 id="when-to-use-alarm-manger-">When to use Alarm manger :</h3>

<p>The Alarm Manager should be used for cases where you want to run your application code at a specific time in future, even if your application is not currently running.</p>

<p>In my case, I had to trigger push notification in 3 and 6 hours,after user has performed an action in the app.</p>

<p>When creating a pendingIntent that will perform a broadcast, 
we need to provide a unique request code parameter for the sender.</p>

<p>The problem was I was passing 0 as <code class="language-plaintext highlighter-rouge">requestCode</code> when creating pending intents for both alarms.</p>

<p><del>PendingIntent.getBroadcast(appContext, 0, intent, 0)</del></p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Intent</span><span class="p">(</span><span class="n">appContext</span><span class="p">,</span> <span class="no">AlarmReceiver</span><span class="o">::</span><span class="k">class</span><span class="p">.</span><span class="nf">java</span><span class="p">).</span><span class="nf">let</span> <span class="p">{</span> <span class="n">intent</span> <span class="o">-&gt;</span>
            <span class="n">intent</span><span class="p">.</span><span class="nf">putExtra</span><span class="p">(</span><span class="no">ARG_RECIPE_ID_KEY</span><span class="p">,</span> <span class="n">recipeId</span><span class="p">)</span>
            <span class="n">intent</span><span class="p">.</span><span class="nf">putExtra</span><span class="p">(</span><span class="no">ARG_ALARM_TYPE</span><span class="p">,</span> <span class="n">alarmType</span><span class="p">.</span><span class="nf">name</span><span class="p">)</span>
            <span class="no">PendingIntent</span><span class="p">.</span><span class="nf">getBroadcast</span><span class="p">(</span><span class="n">appContext</span><span class="p">,</span> <span class="n">unique_id</span><span class="p">,</span> <span class="n">intent</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="p">}</span>

</code></pre></div></div>

<p>Solution:</p>

<p>I created a wrapper to be injected in a class from where I needed to set an alarm.</p>

<script src="https://gist.github.com/waliahimanshu/c0d29361d1dad211fb17f72df1d48bad.js"></script>

<p>Implementation :</p>

<script src="https://gist.github.com/waliahimanshu/f927a9c1745bdd226320630d9fe996ee.js"></script>

<p>Next up, perform long running IO tasks in <code class="language-plaintext highlighter-rouge">BroadcastReceiver.onReceive</code></p>

<p>⏭️ <a href="/android/2019/08/27/goasync-broadcast-receiver.html">GoAsync</a></p>

<hr />]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Problem: I am scheduling multiple alarms using Alarm Manager, but only one gets triggered.]]></summary></entry><entry><title type="html">Bad notification posted from package : Couldn’t create icon: StatusBarIcon</title><link href="https://waliahimanshu.github.io/android/2019/08/16/could-not-create-icon-statusbaricon.html" rel="alternate" type="text/html" title="Bad notification posted from package : Couldn’t create icon: StatusBarIcon" /><published>2019-08-16T00:00:00+00:00</published><updated>2019-08-16T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/android/2019/08/16/could-not-create-icon-statusbaricon</id><content type="html" xml:base="https://waliahimanshu.github.io/android/2019/08/16/could-not-create-icon-statusbaricon.html"><![CDATA[<p><b>Exception</b>:
<em>android.app.RemoteServiceException: Bad notification posted from package : Couldn’t create icon: StatusBarIcon</em></p>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Android">Android</a></p>
</div>
 
  
</div>

<h3 id="fix">Fix</h3>
<p><em>Use alpha only icon.</em></p>

<h3 id="what-are-alpha-only-icons">What are alpha only icons?</h3>
<p>Alpha only icons are transparent icons, where 
<em>white acts as the visible area and black acts as the transparent area</em>.
For example, all <a href="https://material.io/resources/icons/?style=baseline">material icons</a>
are alpha only.</p>

<h3 id="reason">Reason</h3>
<p>Since android L onwards :</p>
<blockquote>
  <p>The system ignores all <em>non-alpha channels</em> in action icons and the main notification icon. 
You should assume that these icons are alpha-only.</p>
</blockquote>

<p>So this exception occurs when colored image resource is used as a notification icon.</p>

<h3 id="why-cant-use-colored-image-resource-">Why can’t use colored image resource ?</h3>
<p>Device status bar backgrounds color could be of any color.
There are tons of manufactures and people apply themes etc.</p>

<p>So Android framework only allows alpha only icons as they will be visible on any colored status bar.</p>

<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nc">NotificationCompat</span><span class="o">.</span><span class="na">Builder</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">channelId</span><span class="o">)</span>
 <span class="o">.</span><span class="na">setSmallIcon</span><span class="o">(</span><span class="no">R</span><span class="o">.</span><span class="na">drawable</span><span class="o">.</span><span class="na">ic_alpha_icon_for_notifications</span><span class="o">)</span> <span class="c1">//alpha only icon</span>
 <span class="o">.</span><span class="na">setColor</span><span class="o">(</span><span class="nc">ContextCompat</span><span class="o">.</span><span class="na">getColor</span><span class="o">(</span><span class="n">applicationContext</span><span class="o">,</span> <span class="no">R</span><span class="o">.</span><span class="na">color</span><span class="o">.</span><span class="na">green</span><span class="o">))</span> 
 <span class="c1">// adds your brand color over alpha icon</span>
</code></pre></div></div>

<hr />]]></content><author><name>waliahimanshu</name></author><category term="Android" /><summary type="html"><![CDATA[Exception: android.app.RemoteServiceException: Bad notification posted from package : Couldn’t create icon: StatusBarIcon]]></summary></entry><entry><title type="html">Wisdom from Naval- Happiness</title><link href="https://waliahimanshu.github.io/personal/2019/08/12/naval-wisdom-Happiness.html" rel="alternate" type="text/html" title="Wisdom from Naval- Happiness" /><published>2019-08-12T00:00:00+00:00</published><updated>2019-08-12T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/personal/2019/08/12/naval-wisdom-Happiness</id><content type="html" xml:base="https://waliahimanshu.github.io/personal/2019/08/12/naval-wisdom-Happiness.html"><![CDATA[<h3 id="notes-from-joe-rogan-podcast-with-naval">Notes from Joe Rogan podcast with Naval</h3>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Personal">Personal</a></p>
</div>
 
  
</div>

<h3 id="happiness">Happiness:</h3>
<p>If fitness can be choice, health can be choice, nutrition can be a choice, working hard and making money can be a choice than <em>happiness can also be a choice</em>.</p>

<blockquote>
  <p><em>What is a desire</em> ?
A contract to make yourself un-happy and suffer, until you get what you want.</p>
</blockquote>

<p>Question to ask every time you are un-happy ? 
What is the underline desire, I am looking to fulfil.</p>

<p>Don’t have too many desires and pick them unconsciously, or have thousands of them. For example, my coffee is too dark, it’s too hot here, there is a cat litter in my garden, small things will eat up your energy.
Pick one overwhelming desire and suffer on that and let other let go. Save your energy for that one desire.</p>

<p>We live in the age of ultimate leverage, your action can be multiplied by thousand fold by:</p>
<ul>
  <li>Broadcasting to podcast</li>
  <li>Investing capital</li>
  <li>People working for you</li>
  <li>By writing code</li>
</ul>

<p>So the impact of good decision making is much higher than it’s used to be. And happy, calm and a peaceful person will make better decisions with better outcomes.</p>

<p>In order to stay peaceful and happy, block:</p>
<ol>
  <li>any outrage, stupidity on social media and in your surrounding.</li>
  <li>snippets taken out of context, modified shared on news and in social media. If paid attention, they will clutter the mind.</li>
  <li>The world reflects your own feeling back at you. The more you judge (annoy by little things) the more you separate from others, see negative things.</li>
  <li>Watch your own thoughts, why i am having that thought does this serve me anymore, often when you understand why you have that thought, you feel calmer.</li>
</ol>

<p><em>Ancient Struggle</em>, were against other tribes, religion and food.
<em>Modern society struggles</em>, is with yourself.</p>

<p>Parents, friends don’t live nearby, no tribal meaning, no religion connection.
When they come to attack you : social media algorithms, video games, sugar, porn you stand alone
These all are diseases of abundance, over exposure to everything, so *the way to survive is to be ascetic, retreat from society beliefs. <em>Turn it off</em></p>

<p><a href="http://www.youtube.com/watch?v=OqlfWDyS1Io" title="The Modern Struggle - Naval Ravikant"><img src="http://img.youtube.com/vi/OqlfWDyS1Io/0.jpg" alt="" /></a></p>

<p>Meditation :</p>
<ul>
  <li>It is an art of doing nothing.</li>
  <li>Monkey mind is a disease, learn to rest your mind.</li>
  <li>Regrets, issues, problem, gets pilled up over time, therefore its necessary to sit down and close your eyes. Let your thoughts pass, don’t judge, don’t react and analyse.</li>
</ul>

<blockquote>
  <p>Peace is happiness at rest</p>
</blockquote>

<h2 id="random-thoughts-and-quotes">Random thoughts and Quotes</h2>
<blockquote>
  <p>Work like lion, hunt, sprint, reset, re-access, feedback, sprint again.</p>
</blockquote>

<blockquote>
  <p>Every man has 2 life , and second start when he realise he has one.</p>
</blockquote>

<blockquote>
  <p>You have got one life, do many different things</p>
</blockquote>

<h2 id="what-is-the-meaning-of-life">What is the meaning of life?</h2>

<p>If there was a single answer, then we will compete with each other.
Answers are paradox, pointless to pursue, but the act of pursing is useful.</p>

<p>Do hard things in life, to make meaning of your life, and 
making money is fine one.
*IT is NOT EASY. IT IS THE FREAKING HARDS THING YOU WILL  DO *
<em>but also the most rewarding one.</em></p>

<p>Just :</p>

<ul>
  <li>Smile more.</li>
  <li>Hug more.</li>
  <li>Go out in nature and in Sunlight.</li>
  <li>Happy thoughts disappear and negative linger, but you can trick your mind by looking positive aspects in every scenario.</li>
</ul>

<hr />]]></content><author><name>Himanshu</name></author><category term="Personal" /><summary type="html"><![CDATA[Notes from Joe Rogan podcast with Naval]]></summary></entry><entry><title type="html">Wisdom from Naval- Wealth</title><link href="https://waliahimanshu.github.io/personal/2019/07/28/naval-wisdom-wealth.html" rel="alternate" type="text/html" title="Wisdom from Naval- Wealth" /><published>2019-07-28T00:00:00+00:00</published><updated>2019-07-28T00:00:00+00:00</updated><id>https://waliahimanshu.github.io/personal/2019/07/28/naval-wisdom-wealth</id><content type="html" xml:base="https://waliahimanshu.github.io/personal/2019/07/28/naval-wisdom-wealth.html"><![CDATA[<h3 id="notes-from-joe-rogan-podcast-with-naval">Notes from Joe Rogan podcast with Naval</h3>

<div class="post-categories">
  
  
<div class="dashed">
<p>#<a href="/categories/#Personal">Personal</a></p>
</div>
 
  
</div>

<p>Top three things everyone seeks :</p>

<ul>
  <li>Wealth.</li>
  <li>Happiness.</li>
  <li>Health.</li>
</ul>

<p>Lets talk about wealth :</p>

<p>We will not become rich by renting our time. We rent our time to our employer,and in return get a monthly salary.  The employer, dictates how, what and where should we work. We don’t earn when we are on vacation and when we sleep.</p>

<p>Sure, hard work is important, but one does not simply can become wealthy by working hard, we have to work on the right thing, with the right people. A man down on a grocery store is not working any less than Elon Musk.</p>

<p>One can become rich by :</p>
<ul>
  <li>Owning a piece of business.</li>
  <li>Having an equity as an owner or an investor.</li>
  <li>Becoming a share holder of a brand.</li>
  <li>Having leverage of people, media or code.</li>
</ul>

<blockquote>
  <p>Lack of material possessions can make you <em>un-happy</em> but getting rich can not make you <em>happy</em>, either.</p>
</blockquote>

<h4 id="everyone-can-be-rich"><span style="color:black">Everyone can be rich!</span>:</h4>

<ul>
  <li>Lowering your lifestyle.</li>
  <li>Making enough money, far more than your burn rate.</li>
  <li>Lot of money saved up and the passive income from that covers your burn rate, keep your burn rate low. (ex do a remote job, live on low cost country or neighborhood hood and save money.)</li>
  <li>Drive your burn rate to zero …become a monk (Don’t do that if you are reading this.)</li>
  <li>Do something you love, you love so much it’s not about money anymore for you.</li>
  <li>Have specific knowledge and skill set.
    <ol>
      <li>Be authentic, what you do.</li>
      <li>Map that to what society wants.</li>
      <li>Leverage (in form of people, money or media).</li>
      <li>Put your name on it, take the risk but you gain the rewards. High risk/ High reward situation.</li>
    </ol>
  </li>
  <li>Ignore your peers, upgrading lifestyle, buying unwanted things which you don’t actually need or to impress others.</li>
  <li>Find the thing you know and do better than anybody else, because you love to do it. Something, for others its work, but for you its play, so no one can outnumber you, because you are authentic.</li>
</ul>

<p>Industrial model of organizations are going to change: Boss’s, hierarchy and processes (which slows you down) We can see these days, with the advent of remote work and #digital nomads
More and more people like to own their schedule, own their time and place and time where they are most productive.</p>

<p>In short people are favouring <em>time and location independence</em>.</p>
<blockquote>
  <p>Retirement is when you stop sacrificing today for some 
imaginary tomorrow.</p>
</blockquote>

<p>⏭️ <a href="/personal/2019/08/12/naval-wisdom-Happiness.html">Happiness</a></p>

<hr />]]></content><author><name>Himanshu Walia</name></author><category term="Personal" /><summary type="html"><![CDATA[Notes from Joe Rogan podcast with Naval]]></summary></entry></feed>